[plt-scheme] #%app literal does not match in syntax-case pattern

From: Marco Monteiro (masm at acm.org)
Date: Fri Nov 20 20:45:18 EST 2009

On Sat, Nov 21, 2009 at 12:39 AM, Eli Barzilay <eli at barzilay.org> wrote:

> On Nov 20, Marco Monteiro wrote:
> > One thing I forgot to mention: define, define-values and lambda in
> > the code fragments are from the scheme language. If I didn't
> > code-walk (or expand on the reader), I wouldn't be able to store the
> > expanded code, right?  The problem, in this case, is hygiene (I
> > can't replace scheme's define-values because define expands to it)
> > and the quote: the code inside it is not expanded.
>
> Yes, if you want the expanded code then you need to expand it -- but
> why do you need to walk over the code?  Or maybe you're talking about
> some compilation step of the expanded code (which is not what code
> walkers are usually used for in CL, at least IIRC).
>
>
It may not be necessary (maybe this is implemented already somewhere
in the library), but here is what I do:

Given, in a module context:

(define (x) (* x x))

I want to get:

(list 'define-values '(x) (list '#%app '* 'x 'x))

I export #%module-begin from my language that wrap every immediate
subform in a X macro. The X macro takes the (define-values (x) (* x x)) form
and returns (list 'define-values '(x) (Y (* x x))). The Y macro code-walks
the
forms: it takes (* x y) and returns (list #'app (Y *) (Y x) (Y x)). Finally,
we get what we
want. The Y macro uses local-expand.

This is a simplification. The Y macro returns more than symbols and
lists of symbols. For example, it may expand to an expression
that builds a syntax tree with location information.

Is there a better way to get the expansion as given in the example above?
Maybe something that recursively applies local-expand to subforms. If there
is, I can use that and then traverse all the expanded code in one go.

Thanks.

Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20091121/823a5e33/attachment.html>

Posted on the users mailing list.