[plt-scheme] Macro problem: struct name coincides with macro keyword

From: Ryan Culpepper (ryan_sml at yahoo.com)
Date: Wed May 3 17:58:00 EDT 2006

--- Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
> Ryan Culpepper wrote:
> > --- Lauri Alanko <la at iki.fi> wrote:
> >>On Wed, May 03, 2006 at 06:36:16PM +0200, Jens Axel Søgaard
> wrote:
> >>>  (require (lib "42.ss" "srfi"))
> >>>
> >>>  (list-ec (: j (index i)'(a b c))
> >>>           (list i j))
> >>>  (define-struct index (lexicon positions))
> >>
> >>>  index: illegal use of syntax in: (index i)
> 
> > I agree with both of your points, except in the first solution,
> the
> > srfi should define index as a macro that blows up when used out
> of
> > context:
> > 
> > (define-syntax index
> >   (lambda (stx)
> >     (raise-syntax-error #f "used out of context" stx)))
> 
> Changing 42.ss did do the trick.
> 
> But - suppose I can't change the library in question, what then?

In that case, the least painful solution is to call your struct
something else. Your idea of making an identifier macro will not
work, because comparing identifiers doesn't involve expanding them,
so your macro would never get called.

Ryan



Posted on the users mailing list.