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

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed May 3 12:36:16 EDT 2006

Without modules I can do this:

   (require (lib "42.ss" "srfi"))

   (list-ec (: j (index i)'(a b c))
            (list i j))
   (define-struct index (lexicon positions))

   (list-ec (: j (index i) '(a b c))
            (list i j))

and get ((0 a) (1 b) (2 c)) twice.


Within a module like

(module indexer mzscheme
   (require (lib "42.ss" "srfi"))

   (list-ec (: j (index i)'(a b c))
            (list i j))
   (define-struct index (lexicon positions))

   )

I get

   index: illegal use of syntax in: (index i)

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.

My second idea was to make an identifer macro that
expands to an 42.ss index. Something like this:

  (define-syntax (Index stx)
   (syntax-case stx ()
      [_ (syntax/loc <what-goes-here?> #'index)]))

Is this the best approach? And what should
<what-goes-here?> be?

-- 
Jens Axel Søgaard
<http://www.scheme.dk/blog/>




Posted on the users mailing list.