[racket] Macros, Eval and dynamic syntax?

From: Scott Klarenbach (scott at pointyhat.ca)
Date: Wed Apr 17 14:29:27 EDT 2013

Hi there,

With my limited macro knowledge I'm trying to accomplish the following:

Create a macro that accepts custom dsl-ish syntax.  In addition to the
custom syntax, a user can also provide a procedure.

For example:

(my-macro [(name:first-name type:string required:#t)
                  (name:last-name type:string)
                  (hash 'id middle-name 'type 'string)
                  (lambda () (do-something-arbitrary))])

The first two are the dsl, the next two are procedures.  The macro converts
the shorthand key:val syntax into hashes internally and does some other
processing.  So far, so good.

But additionally I'd like to invoke any provided procedure (any datum that
doesn't match the dsl syntax) in lieu of the short-hand syntax.

What's the "correct" way to invoke the procedures, since I'm sure I'm doing
it wrong.

So far, I'm converting each syntax expression that's not in the dsl using
syntax-datum.  But then they're quoted, and I have to use eval, which
imposes a bunch of namespace complexity.  Is there a way to invoke syntax
without eval?  Or is there a much better way entirely to write the macro so
that the above would work?


Talk to you soon,

Scott Klarenbach

PointyHat Software Corp.
p 604-568-4280
e scott at pointyhat.ca
200-1575 W. Georgia
Vancouver, BC V6G2V3

To iterate is human; to recur, divine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130417/3648dbf3/attachment.html>

Posted on the users mailing list.