[racket] Macro stepper expansion

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Tue May 22 16:38:06 EDT 2012

On 05/21/2012 08:13 PM, Harry Spier wrote:
> I've entered the following example from the Racket Guide into DrRacket
> #lang racket
> (define-syntax-rule (swap X Y)
>    (let ([tmp X])
>      (set! X Y)
>      (set! Y tmp)))
> (let ([tmp 5] [other 6])
>    (swap tmp other)
>    (list tmp other))
> It gives me the correct result:
>> '(6 5)
> But  when I stepped through it with the macro expander I got:
>   [Macro transformation]
> (module anonymous-module racket
>    (#%module-begin
>     (define-syntax-rule
>      (swap X Y)
>      (let ([tmp X]) (set! X Y) (set! Y tmp)))
>     (let ([tmp 5] [other 6])
>       (let ([tmp tmp]) (set! tmp other) (set! other tmp))
>       (list tmp other))))
> I was expecting to see something like the Racket Guide description in
> section 16.1 I.e:
> "Racket doesn’t produce the naive expansion for the above use of swap.
> Instead, it produces
> (let ([tmp 5]
>        [other 6])
>    (let ([tmp_1 tmp])
>      (set! tmp other)
>      (set! other tmp_1))
>    (list tmp other))            "

The Guide should really say that it produces something *equivalent* to 
the code above. It doesn't actually change the names; the information is 
stored "out of band" as Mark and Rename wraps attached to the syntax 
object. The macro stepper renders Marks using colors: some of the 'tmp's 
should be red (or some other color besides black).


Posted on the users mailing list.