[racket] Again on bindings visibility in eval

From: Markku Rontu (markku.rontu at iki.fi)
Date: Thu Jul 14 14:35:23 EDT 2011

Hi Eli,

On Thu, Jul 14, 2011 at 6:04 PM, Eli Barzilay <eli at barzilay.org> wrote:

> Commet for the short-attention-spanners: read this:
>
>  http://blog.racket-lang.org/2011/04/writing-syntax-case-macros.html
>
>
Thanks for writing this. It is so far the best introduction to this matter
I've seen.


> 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
> you.)
>

Still, I count it as good eye opening material :) Granted your cited blog
post is good too but it's not a complete tutorial.


> If you're working in Racket, it makes much more sense to really use
> its syntax system rather than stick to those tricks.
>
>
However, I find syntax-case to be very similar if you proceed to it as next
step from syntax-rules. I mean that if you take it as an improved
syntax-rules, you will likely end up using it just like syntax-rules except
for the part about breaking hygiene. This is just my experience.



> > 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
> `syntax-rules'...
>
> > 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.
>

I think what is mainly missing is a bit more positive publicity in this
area. A great collection of tools for writing macros exists, and obviously
great things are being written using them (TR etc.). Just need to produce
enough material so that the search engines start to find the good stuff.

-Markku
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110714/3df20aaa/attachment.html>

Posted on the users mailing list.