[racket] Macros with Flexible Sub-Forms like (class...)

From: Scott Klarenbach (scott at pointyhat.ca)
Date: Sat Feb 23 14:22:33 EST 2013

What is the best approach for creating a macro that parses sub-forms in any
order, similar to the way (class ...) works in Racket?

I'm writing a simple sql-like dsl, and originally I had syntax that used
keyword-params, as in:

(query client-table #:select "first-name" #:where "type = 3")

but I'm wondering how to go about achieving something more like:

(query client-table
  (select "first-name, address.city-id")
  (where "client-type = 3"))

The order of the sub-forms shouldn't matter.

I've seen this style everywhere, from emacs-lisp to racket classes, and
just wondering if my thinking is correct.

Should I just loop through the body syntax forms and pass to (match...) in
order to process them?  Or is this type of nested form style something for
which there is a higher level abstraction already built into the macro
system?

For example, (select ...) should be it's own macro capable of being
composed not just within (query...) but in other contexts as well.  But I'd
want to limit such contexts so that one can't call (select...) outside one
of these pre-allowed parent forms.  All of this implies a lot of boiler
plate and so I figured maybe I'm creating too much work for myself by
attempting to do it all manually.

Thanks a lot.

-- 
Talk to you soon,

Scott Klarenbach

PointyHat Software Corp.
www.pointyhat.ca
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/20130223/68788388/attachment.html>

Posted on the users mailing list.