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

From: Lauri Alanko (la at iki.fi)
Date: Wed May 3 12:55:08 EDT 2006

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 mentioned a related problem a while ago:

http://list.cs.brown.edu/pipermail/plt-scheme/2006-March/012013.html

> My first thought was to rename the imported "index" from 42.ss,
> but index is not exported from 42.ss! It is used purely as
> a keyword.

What happens is that the the srfi-42 macros define the (usually unbound)
_top-level_ identier "index" to be the special keyword, and you shadow
that with your struct definition. You need to somehow import the
top-level variable with a new name, but I'm not sure if that is
possible. There is no "top-level" module...

The real problem is with the srfi-42 implementation: it should define a
dummy variable named "index" that acquires the keyword property (instead
of the top-level variable). Then it could be imported and renamed
normally. Alternatively (and I prefer this), since the keyword cannot
appear in the same position as an expression, it should be compared
just using its literal form instead of module-identifier=?.


Lauri


Posted on the users mailing list.