[plt-scheme] Re: Newbie question: using a macro to create a top-level variable?

From: Gregg Williams (spamme at innerpaths.net)
Date: Sat Aug 22 23:56:23 EDT 2009

Thanks for the exceedingly clear explanation of what works and why.
Not only do I have a choice of solutions for my immediate situation,
but I also learned something you about define-syntax-rule: namely,
that there can be arbitrary syntax in the pattern as well as the
template. I never would have thought to put the apostrophe into the
pattern "(infoml:make-rack 'rack-id)". Thanks again for your help.

>
> The thing is that you want to quote one place only.  An easy way to do
> this is:
>
>   (define-syntax-rule (infoml:make-rack rack-id)
>     (define rack-id (infoml:make-rack-manual 'rack-id)))
>   (infoml:make-rack ideas) ; no quote
>
> You can do this with the quote:
>
>   (define-syntax-rule (infoml:make-rack 'rack-id)
>     (define rack-id (infoml:make-rack-manual 'rack-id)))
>   (infoml:make-rack 'ideas)
>
> This looks like it's working, but what's really happening is that the
> scheme reader sees:
>
>   (define-syntax-rule (infoml:make-rack (quote rack-id))
>     (define rack-id (infoml:make-rack-manual (quote rack-id))))
>
> and `quote' is just a pattern variable that matches anything.  So if
> you enter
>
>   (infoml:make-rack (add1 ideas))
>
> it actually expands to
>
>   (define ideas (infoml:make-rack-manual (add1 ideas)))
>
> To make this way work, you can use the more explicit `syntax-rules',
> and specify `quote' as a keyword:
>
>   (define-syntax infoml:make-rack
>     (syntax-rules (quote)
>       [(_ (quote rack-id))
>        (define rack-id (infoml:make-rack-manual (quote rack-id)))]))
>
> and doing this should make it clear that this is all redundant since
> the `quote' requirement is just an arbitrary piece of syntax that
> isn't really doing anything.
>
> --
>           ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                  Maze is Life!
> _________________________________________________
>   For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.