[racket] Again on bindings visibility in eval

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jul 14 11:04:36 EDT 2011

Commet for the short-attention-spanners: read this:


5 hours ago, Markku Rontu wrote:
> This tutorial helped me to understand some basics of macros. For
> example how to generate code with them. Now Racket has lots of other
> facilities as well but maybe these give you ideas how to ask more
> precise questions?
> http://hipster.home.xs4all.nl/lib/scheme/gauche/define-syntax-primer.txt

This is *not* a good tutorial for using macros in Racket.  When you're
dealing with macro systems, the Scheme world has always agreed that
having hygienic macros is a good idea, but there was no agreement on
anything more low-level than `syntax-rules', and different
implementations use different systems.  As a result of only
`syntax-rules' being in the report, it became somewhat popular out of
necessity for people who want to write portable code.  But the bottom
line is that this is really not a good way to write macros -- you're
basically confining yourself to a rewrite system which is very hard to
deal with, and after a lot of teeth grinding you eventually implement
enough rewrites to have a lambda-calculus like thing that you can use
to do a bit more programming.  (And this is where this tutorial takes

If you're working in Racket, it makes much more sense to really use
its syntax system rather than stick to those tricks.

> On the topic of macros, I find it a bit confusing that to
> metaprogram in Racket, I must use such a different language of
> macros (with syntax-rules et al.), instead of being able to
> manipulate common data structures with plain old Racket functions.

This confusion (as have been pointed in other replies) is a direct
result of reading that tutorial and thinking that you must use only

> The approach in Clojure, that the code is just a common data
> structure, easily manipulatable with Clojure code, is
> intriguing. What I must do with syntax-rules et al. brings me
> memories of template metaprogramming in C++, where I had to twist my
> mind in order to be able to do the most simple of things. Writing
> regular tree manipulation in Racket is easy, but manipulating the
> syntax tree with the macro support is not because of this "language
> switch".

...and with that limitation in place, this criticism is absolutely
correct.  It's a nice description for why you should really *not*
limit yourself to only `syntax-rules'.

Read that blog post: it shows you how you can use plain racket code to
write macros -- and it introduces some of the tools that make it easy
to deal with syntax values.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.