<div class="gmail_quote">On Sat, Nov 21, 2009 at 12:39 AM, Eli Barzilay <span dir="ltr">&lt;<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>&gt;</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">&gt; One thing I forgot to mention: define, define-values and lambda in<br>
&gt; the code fragments are from the scheme language. If I didn&#39;t<br>
&gt; code-walk (or expand on the reader), I wouldn&#39;t be able to store the<br>
&gt; expanded code, right?  The problem, in this case, is hygiene (I<br>
&gt; can&#39;t replace scheme&#39;s define-values because define expands to it)<br>
&gt; 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&#39;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 &#39;define-values &#39;(x) (list &#39;#%app &#39;* &#39;x &#39;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 &#39;define-values &#39;(x) (Y (* x x))). The Y macro code-walks the<br>forms: it takes (* x y) and returns (list #&#39;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>