[racket] keyword arguments in define-syntax-rule

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Aug 10 13:24:00 EDT 2011

At Wed, 10 Aug 2011 10:58:34 -0600, Jon Rafkind wrote:
> Can `define-syntax-rule' support keyword arguments? Preferably keywords
> with default values.
> (define-syntax-rule (foo #:x [x 5]) x)
> (foo)
> (foo #:x 2)
> If this sounds like a good idea and could be implemented I can give it a
> whirl.

I don't think it would be a good idea.

A keyword in the pattern language of `define-syntax-rule' and
`syntax-rules' is a literal. For simple cases like `foo', you can write

 (define-syntax foo
   (syntax-rules ()
     [(_) 5]
     [(_ #:x x) x]))

Supporting combinations of keywords quickly gets out of hand, at which
point you want `syntax-parse'.

Existing `syntax-rules' and `syntax-case' macros certainly use keywords
as literals. I don't know of a `define-syntax-rule' macro that uses
keywords, but I think the pattern language of `define-syntax-rule'
shouldn't be different from the pattern language of `syntax-rules'.
Overall, general keyword handling seems like a job best left to

Posted on the users mailing list.