[plt-scheme] Very basic macro question

From: Laurent (laurent.orseau at gmail.com)
Date: Sun Jan 17 09:58:27 EST 2010

Hi,

On Sun, Jan 17, 2010 at 15:22, johny seventy <johnyseventy at hotmail.com>wrote:

>  Hi!
>
> I am trying to learn syntax-rules macros but have some very basic questions
> regarding manipulation of s-expressions.
>
> Below is some simple code to illustrate my questions:
>
> #lang scheme
>
> (define-syntax foo
>   (syntax-rules ()
>     ((_ (x y))
>      #t)))
>

instead of #t, try to return '(y x), it is more informative.


>
>
> (define sexpr '(a b))
>
> ;; one
> (foo sexpr)
>
> ;; two
> (foo '(a b))
>

this works because it matches (quote (a b)), so x becomes `quote' and y
becomes (a b).


;; three
> (foo (a b))
>
> ;; four
> (eval `(foo ,sexpr))
>

For this one, I won't answer it as I'm not sure myself, but it seems that
eval can/must almost always be avoided.



> So I understand why the first example fails. I am not sure why example two
> matches as I would only assume example three would. I understand why example
> four works but is there anyway I can do this without eval?
>
> TIA.
>

My 2 cents.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100117/ad8bd242/attachment.html>

Posted on the users mailing list.