[racket] Basic Questions Regarding Macros

From: Jos Koot (jos.koot at telefonica.net)
Date: Wed Aug 31 15:23:22 EDT 2011

The literals are there to make sure that a given identifier in a macro call
has the same binding as asumed by the macro itself.
#lang racket
(define-syntax is-a?
  (syntax-rules (a)
    ((_ a) 'yes)
    ((_ _) 'no)))
(define a 'whatever)
(is-a? a) ; yes
(let ((a 'something-else)) (is-a? a)) ; no


From: users-bounces at racket-lang.org [mailto:users-bounces at racket-lang.org]
On Behalf Of Todd Bittner
Sent: miércoles, 31 de agosto de 2011 19:41
To: users at racket-lang.org
Subject: [racket] Basic Questions Regarding Macros


I'm a newcomer to Racket, and, so far, I love it.  The language is a joy,
and the documentation is well-written, but I find myself struggling a bit
with the section in The Guide on macros.

In regards to syntax-rules and syntax-id-rules there is 'literal-id'
parameter that I don't understand.  In the syntax-rules example with rotate,
it's left blank, but in the syntax-id-rules example with clock, it's
populated with 'set!'.  What specific purpose does this serve?  It seems to
me that the syntax for set! would be matched in the pattern below 'set!
clock e', so I don't know what other information it imparts.

Also, syntax-id-rules seems to be used, as stated in the documentation, for
cases where the macro form won't follow an open parenthesis, and when using
set!.  I know that set! is a special mutator function, but it seems strange
to me that one function has an entirely special case.

Finally, reading through the reference, #' serves, I believe, as shorthand
for (syntax), but in what practical situations would I then call it?

Thanks for the help,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110831/e5fc242a/attachment.html>

Posted on the users mailing list.