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

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Sat Feb 23 20:49:43 EST 2013

On 2013-02-23 12:34:58 -0800, Scott Klarenbach wrote:
>    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...:)

You can just bind the sub-forms to syntax transformers that raise
errors. For example,

  (define-syntax name (syntax-rules ()))

or, more informatively:

  (define-syntax (name stx)
    (raise-syntax-error 'name "only valid inside new-person"))

and then provide `name` from your library. If you do this, it's probably
best to use `~literal` instead of `~datum` in your parse patterns.


Posted on the users mailing list.