[plt-scheme] Keyword argument macros
At Tue, 6 Jan 2009 06:43:33 -0600, "Casey Klein" wrote:
> I'd like to write a macro that accepts keyword arguments, e.g.,
> (my-macro e1 #:kw e2 e3). syntax-case isn't much help in parsing the
> macro's input. Do I need to do this parsing myself, checking for
> duplicate/missing keywords, or is there some library solution I'm
> missing?
I don't think you're missing anything.
I've implemented form using something like
(syntax-case stx ()
[(_ #:optional-stuff a expr ...)
(generate #'(expr ...) #'a)]
[(_ expr ...)
(generate #'(expr ...) #f)])
which works ok (but not great) if the keyword addition has a fixed
position in the form and if there are not many optional parts. For more
complex forms, I've so far resorted to manual parsing.