[plt-scheme] Recognizing datums in macros

From: Lauri Alanko (la at iki.fi)
Date: Wed Feb 8 00:45:15 EST 2006

On Wed, Feb 08, 2006 at 12:16:36AM +0100, Jens Axel Søgaard wrote:
>     (syntax-case stx ()
>       [(define-constant-setter name! datum)

> Is there a way to signal an error if datum is not a datum?

Sure. Add a guard:

(syntax-case (syntax-local-expand #'datum (syntax-local-context) '() #f)
    (#%datum quote)
  ((#%datum . val) #t)
  ((quote val) #t)
  (_ #f))

This also works correctly if quote (or #%datum) has been locally bound
to something else (provided that they are bound to the real things where
this things is defined).


Posted on the users mailing list.