[plt-scheme] 3D boxes and macros

From: Arjun Guha (garjun at cs.brown.edu)
Date: Tue Jul 19 18:05:09 EDT 2005

Consider this code:

(module box-and-macro mzscheme

   (define-for-syntax the-box (box 'initial))

   (define-syntax (my-macro stx)
     (syntax-case stx ()
            (set-box! #,the-box 'value)
            (if (eq? (unbox #,the-box) 'value)

I have a box defined in the transformer environment, that I insert into 
the syntax.  I'd expect that the set-box! would first mutate the contents 
to 'outer-value, followed by the call to unbox.  However, what I get is:

Welcome to DrScheme, version 299.106-svn16jun2005.
Language: (module ...).
> (my-macro)

Could someone tell me what's going on?  Moreover, how I could get what I 
want?  That is, I want an accumulator for macros.  I thought I could hack 
it by creating a box in the transformer environment and accessing/mutating 
it as appropriate.


Posted on the users mailing list.