[plt-scheme] Recognizing datums in macros

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Feb 8 01:06:36 EST 2006

On Feb  8, Lauri Alanko wrote:
> 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)

I think that this gets you the context of the syntax your currently
expanding, so a plain 'expression would be better.

>     (#%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).

Another problem that I encountered recently -- doing this means that
the #'datum will be expanded twice.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.