<div class="gmail_quote"><span class="Apple-style-span" style="font-family: 'Droid Sans', arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(32, 32, 32); "><div>Hi Matthias, hi schemers,</div>
<br><div class="gmail_quote"><div class="im" style="color: rgb(80, 0, 80); ">2011/7/11 Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank" style="color: rgb(103, 117, 58); ">matthias@ccs.neu.edu</a>></span><br>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<br>Now I don't understand at all why you want to use eval in the macro.<br>If the right-hand side just returned the lambda that you have there,<br>it would automatically capture the variables in the context of the<br>
gama rule.<br><br></blockquote><div> </div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
Have you tried just returning the lambda as is from the macro?<br><div><div></div><div><br></div></div></blockquote></div><div>I tried but it doesn't work! Here you find a sample of what you suggest:</div><div>---------------</div>
<div><div>(define-syntax mymacro</div><div> (syntax-rules (prova)</div><div> [(mymacro input ...)</div><div> (lambda (z) (list input ...) (+ z extern-var))]))</div><div><br></div><div>> (let* ((extern-var 2) (f (mymacro x y))) (f 1))</div>
<div>reference to undefined identifier: extern-var</div></div><div>-----------------</div><div>So, it seeems that although I avoid "eval" the problem</div><div>is still there!</div><div><br></div><div>Just to give you more details of my implementation... </div>
<div>In my case things are a little more complicated:</div><div><br></div><div><div>I told you that the gamma-rule is "similar" to a lambda, not a lambda.</div><div>In order to separate gamma-rules form normal procedures I defined</div>
<div>a structure for gamma-rules like this:</div><div><br></div><div> ; Rule datatype definition</div><div> (define-values (s:gamma make-gamma gamma? gamma-ref gamma-set!)</div><div> (make-struct-type 'gamma #f 3 0 #f ...))</div>
<div><br></div><div>the first field is the procedure resulted form the lambda evaluation (it is the lambda generated by the "replace" macro, and the lambda code generation depends on the gamma-rule inputs), the other fields are parameters of the rule, like "active" or "inactive", etc.</div>
<div><br></div><div>so the "replace" macro does not return a lambda, but a struct whose </div><div>first field is a procedure resulting from: (eval `(lambda ...)):</div><div><br></div><div>(define-syntax replace-once </div>
<div> (syntax-rules (replace-once) </div><div> [(replace input ...)</div><div> (let* (...compute some parameters "x" "y" from input...)</div><div> (make-gamma </div>
<div> (eval </div><div> (quasiquote </div><div> (lambda (cntx) </div><div> ...unquote "x" and "y" to generate specific code ...</div>
<div> ...some references to external symbols ... </div><div> )))</div><div> <field2></div><div> <filed3>))]))</div></div><div><br></div><div>I know that my implementation seems to be complicated,</div>
<div>but, since I have a "new language" running on scheme, I would like to</div><div>have multisets and (chemical) gamma rules defined as new structures different from similar native structures of racket (i.e. vectors and procedures).</div>
<div><br></div><div>From what you say I understand I HAVE TO AVOID EVAL...</div><div>... and up to now I don't find another solution to generate the</div><div>lambda, other than "(eval (quasiquote (lambda (...) ...))".</div>
<div class="im" style="color: rgb(80, 0, 80); "><div><br></div><div>Thank you for your attention.</div></div><div>If you mind some "eval" alternatives that are able to capture</div><div>local binding (i.e. the local environment), please let me know.</div>
<div>Browsing the racket documentation I found some alternative "eval"</div><div>version (r5rs):</div><div><br></div><div>(eval expr evironment-specific)</div><div><br></div><div>but it seems it allows only to capture a specified namespace</div>
<div>bunding... I will spend some time to look at it!</div><div><br></div><div>Cheers,</div><div><br></div><font color="#888888"><div>Maurizio. </div></font></div></span></div>