[plt-scheme] expand

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jul 11 20:27:13 EDT 2002

At Thu, 11 Jul 2002 17:39:13 -0400 (EDT), David Feuer wrote:
> I can't figure out why the following gives an error.  Can someone help?
> (let-syntax ((foo (lambda (obj)
>                     (syntax-case obj ()
>                       ((_ q) (expand (syntax q)))))))
>   (let ((y 3)) (foo y)))
> It seems that expand somehow makes the macro system lose track of the
> origin of y, but I don't see why.

To expand a sub-expression during the expansion of an enclosing
expression, use `local-expand' instead of `expand'.

The `expand' function expands a complete expression in such a way that
re-`expand'ing the result works as expected. Due to the interaction of
"marks" and "renamings" in the syntax-case machinery, repeated `expand'
calls turn out to be incompatible with expanding sub-expressions. (For
the same reason, `expand'ing the result of `expand-once' doesn't always
give the same result as `expand'ing the original expression.) I haven't
yet figured out whether this incompatibility is fundamental or merely
an artifact of using marks and renaming for hygiene.


Posted on the users mailing list.