Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

GODDAMN QUOTING IN RACKET

Name: Anonymous 2010-11-18 17:31

I'm trying to demonstrate to someone a simple case dispatch on a list.

The idea is something like:

(define (math x y)
        (unquote (get-math x) y))

Where y is a list and:

(define (get-math x)
        (cond ((= x 1) '+)
              ((= x 2) '-)
              ((= x 3) '*)
              ((= x 4) '/)))

But, Racket just doesn't use normal quoting rules, like I can only unquote if I'm already in a quote, but I can't pass an unquote to an argument, or nor use unquote in a definition without being a quote anyways, which is RETARDED.

tl;dr quote comes BEFORE unquoting, what do?

Name: Anonymous 2010-11-18 17:49

eval/apply

Name: Anonymous 2010-11-18 19:50

(define (math x y)
  (apply (get-math x) y))

(define (get-math x)
  (case x ((1) +)
          ((2) -)
          ((3) *)
          ((4) /)))

Name: Anonymous 2010-11-18 19:52

>>3
(define (math x . y)
FTFY

Name: Anonymous 2010-11-18 20:05


#lang racket
(define (anus x)
  (cond
    ((= x 0) 1)
    (else (* x (anus (- x 1))))))

Name: Anonymous 2010-11-18 20:18

(define(x y)(if(zero? y)1(* y(x(-1 x)))))

Name: Anonymous 2010-11-19 1:00

Some of you aren't getting it.

If I just put in (math 1 (4 5)), (4 is no a valid operator, etc. If I put in (math 1 '(4 5)), there aren't any normal operators to remove the quote. Rackets quoting system is all fucked up, like you can only do (quasiquote (unquote (+ 1 2))) and it'll return 3, but if you try anything else it just shits the bed, like there's just no command to unquote a list.

Name: Anonymous 2010-11-19 1:36

Are you aware that quoting something doesn't return some kind of special quoted-datatype, but just a list/symbol, that you can't unquote something outside a quasiquotation because (unquote '(1 2 3)) and (unquote (list 1 2 3)) would be the same thing and that you should just return your fucking function, not the symbol and that if you really want to be a fucking faggot you should use eval?
IHBT

Name: Anonymous 2010-11-19 2:33

>>1
What the fuck did you expect to have happen? It's like you have no idea what quote/quasiquote/unquote is for. Use apply, like the non-retarded anon above you.

I swear, some people would implement quoting in Kernel.

Name: Anonymous 2010-11-19 3:08

Quoting in kernel done like this: ``example''

Name: Anonymous 2010-11-19 13:08

This would be so easy in Python.

Name: Anonymous 2010-11-19 15:06

This would be so easy in LISP.

Don't change these.
Name: Email:
Entire Thread Thread List