[plt-scheme] 'eval at expansion time

From: Tom Schouten (tom at zwizwa.be)
Date: Sun Jul 19 05:01:51 EDT 2009

Dear list,

I've read a number of posts on this list about replacing the need for
'eval by appropriate use of macros.  Overall, I've found the way
macros are used in PLT Scheme fascinating, and it has been a good
guide to clarify some practical problems I've been struggling with in
the past.

However, recently I've run into a pattern that confuses me.  It has to
do with the observation that 'eval seems to sometimes be the simplest
way to turn source code into an informative data structure at macro
expansion time, such that this can then be used as extra input to a
syntax transformation.  (Abstract Interpretation)

While this feels like a necessary use since 'eval actually does
something that can only be mimicked by implementing something like
'eval, it also feels like a dirty hack in a way I can't really

Concretely, this is about a macro that compiles a dataflow language to
Scheme.  The input syntax is interpreted twice: once to construct a
simplified interpretation as a dependency graph, which is then used to
sort a list of subforms in the original syntax so it can be expanded a
second time into a serial Scheme program.  Concrete code for the two
stages can be found here [1][2].  I use 'eval together with namespace
anchors to implement this.

I guess I'm looking for a name for this pattern or a reason to not use
'eval.  It seems that any alternative would involve higher order
macros in a way I don't quite grasp..

Ideas welcome,

[1] http://zwizwa.be/darcs/staapl/staapl/machine/dfl.ss
[2] http://zwizwa.be/darcs/staapl/staapl/machine/dfl-compose.ss

Posted on the users mailing list.