[racket] Macros in slideshow

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Jan 21 09:45:59 EST 2015

At Wed, 21 Jan 2015 13:04:11 +0000, Reuben Thomas wrote:
> Since I have a lot of slides like this, I want to write a macro. I tried:
> 
> #lang slideshow
> 
> ​(require slideshow/step)
> 
> (define-syntax-rule (correct from to)
>   (lt-superimpose
>    ((vonly before) (t from))
>    ((vonly after) (t to))))
> 
> (void
>  (with-steps
>   (before after)
>   (slide
>    (correct "With" "By"))))
>> ​but I get the error:
> 
> ​vonly: unbound identifier in module in: vonly​
> 
> ​I've experimented with various types of quoting and unquoting, and tried
> define-simple-macro instead of define-syntax-rule, but I'm forced to admit
> I don't know what I'm doing!
> 
> I know that vonly is special and is bound non-hygienically inside the scope
> of the with-steps; how do I reference it correctly in a macro?​

You're right that the essential problem is that `with-steps` introduces
binding no-hygienically. Non-hygienic macros don't compose nicely.

If `with-steps` were written in modern Racket, then it would be
hygienic, where `vonly`, etc., are bindings that take their meaning
as syntax parameters from an enclosing `with-steps`. Fortunately, it's
possible to implement a more modern `with-steps` using the existing one.

Use the enclosed "new-step.rkt" in place of `slideshow/step`, and then
your `correct` macro will work.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: new-step.rkt
Type: application/octet-stream
Size: 2101 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20150121/f64f09ad/attachment.obj>

Posted on the users mailing list.