[racket] Macro expansion

From: Markku Rontu (markku.rontu at iki.fi)
Date: Wed Dec 29 17:45:21 EST 2010


I tried writing some macros to help with my programming but there are
some things I don't get. How would I go about writing the following kind
of macro?

  (inner-macro foo 1 2 3))

The intent is for the inner-macro to generate a form that the
outer-macro is able to see and parse. These two macros don't have
anything to do with each other, except they happen to clash in this
regard, and their use should be orthogonal.

As I understand it, expansion goes so that outer-macro is expanded
first. And that means it sees the syntax (inner-macro foo 1 2 3) and not
the form inner-macro would expand to later. So outer-macro can't see the
syntax inner-macro will produce.

Unless, I am perhaps able to control the expansion from the outer-macro
and have it expand all its contents before going on with its own work.
How would I go about with this?

I tried simple use of expand-syntax but I run into problems of not being
able to see the inner-macro in the environment where outer-macro does
the expand. Another meta level I suppose.

(errors are along the lines of "expand: unbound identifier in module (in
the transformer environment, which does not include the macro definition
that is visible to run-time expressions)" and "expand: unbound
identifier in module (in phase 1, transformer environment)")

I may be doing something foolish This is the first time I am writing a
macro that needs to parse something from syntax that happens to have
macros in it too.


Posted on the users mailing list.