<div class="gmail_quote">On Sat, Nov 21, 2009 at 12:39 AM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Nov 20, Marco Monteiro wrote:<br>
</div><div class="im">> One thing I forgot to mention: define, define-values and lambda in<br>
> the code fragments are from the scheme language. If I didn't<br>
> code-walk (or expand on the reader), I wouldn't be able to store the<br>
> expanded code, right? The problem, in this case, is hygiene (I<br>
> can't replace scheme's define-values because define expands to it)<br>
> and the quote: the code inside it is not expanded.<br>
<br>
</div>Yes, if you want the expanded code then you need to expand it -- but<br>
why do you need to walk over the code? Or maybe you're talking about<br>
some compilation step of the expanded code (which is not what code<br>
walkers are usually used for in CL, at least IIRC).<br>
<div><div></div><br></div></blockquote></div><br>It may not be necessary (maybe this is implemented already somewhere<br>in the library), but here is what I do:<br><br>Given, in a module context:<br><br>(define (x) (* x x))<br>
<br>I want to get:<br><br>(list 'define-values '(x) (list '#%app '* 'x 'x))<br><br>I export #%module-begin from my language that wrap every immediate<br>subform in a X macro. The X macro takes the (define-values (x) (* x x)) form<br>
and returns (list 'define-values '(x) (Y (* x x))). The Y macro code-walks the<br>forms: it takes (* x y) and returns (list #'app (Y *) (Y x) (Y x)). Finally, we get what we<br>want. The Y macro uses local-expand.<br>
<br>This is a simplification. The Y macro returns more than symbols and <br>lists of symbols. For example, it may expand to an expression<br>that builds a syntax tree with location information.<br><br>Is there a better way to get the expansion as given in the example above?<br>
Maybe something that recursively applies local-expand to subforms. If there<br>is, I can use that and then traverse all the expanded code in one go.<br><br>Thanks.<br><br>Marco<br>