Thanks Danny. There's also something I recall for validation, as in the docs for (define/override...) where usage outside of a (class...) form is a syntax error. I'll hunt...:)<br><br><div class="gmail_quote">On Sat, Feb 23, 2013 at 12:19 PM, Danny Yoo <span dir="ltr"><<a href="mailto:dyoo@hashcollision.org" target="_blank">dyoo@hashcollision.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Sat, Feb 23, 2013 at 12:22 PM, Scott Klarenbach <<a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a>> wrote:<br>
> What is the best approach for creating a macro that parses sub-forms in any<br>
> order, similar to the way (class ...) works in Racket?<br>
<br>
<br>
</div>I believe that there's support in the syntax-parse library to parse<br>
these sub-forms in any order. Let me see if I can find the<br>
appropriate documentation... Ah, here:<br>
<br>
<a href="http://docs.racket-lang.org/syntax/Optional_Keyword_Arguments.html" target="_blank">http://docs.racket-lang.org/syntax/Optional_Keyword_Arguments.html</a><br>
<br>
<br>
The documentation here focuses on parsing optional keyword arguments<br>
that can be consumed in any order. The underlying mechanism should<br>
work with non-keywords as well.<br>
<br>
<br>
For example:<br>
<br>
<br>
;;;;;;;;;;;;;;;;;;;;;;;;;<br>
#lang racket<br>
<br>
(require (for-syntax syntax/parse))<br>
<br>
(struct person (name age) #:transparent)<br>
<br>
;; Accept name and age in any order, or even omit them:<br>
(define-syntax (new-person stx)<br>
(syntax-parse stx<br>
[(_ (~or (~optional ((~datum name) name) #:defaults ([name #'"Jane Doe"]))<br>
(~optional ((~datum age) age) #:defaults ([age #'#f])))<br>
...)<br>
#'(person name age)]))<br>
<br>
(new-person)<br>
<br>
(new-person (name "Pen Pen"))<br>
<br>
(new-person (age 48) (name "Gendo Ikari"))<br>
;;;;;;;;;;;;;;;;;;;;;;;;;<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Talk to you soon,<br><br>Scott Klarenbach<br><br>PointyHat Software Corp.<br><a href="http://www.pointyhat.ca" target="_blank">www.pointyhat.ca</a><br>p <a href="tel:604-568-4280" value="+16045684280" target="_blank">604-568-4280</a><br>
e <a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a><br><span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">200-1575 W. Georgia</span><br>
Vancouver, BC <span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">V6G2V3</span><br><br>_______________________________________<br>To iterate is human; to recur, divine