<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 9.00.8112.16430"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=657182323-13072011><FONT color=#0000ff
size=2 face=Arial>It may very well be that I don't understand your point (it's
late at my place and I already had a couple of wiskeys) but can't you
introduce the variables x and y hygienically. If you have (let ((x ...) (y ...)
...) code) as part of the expansion of a macro, then the code hygienically
catches the bindings. You may also find that in a template 'z, where z is a
pattern variable, does indeed expand to (quote
whatever-was-specified-for-z-in-the-macro-call) So may be you can do without
eval and quasiquote after all.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=657182323-13072011><FONT color=#0000ff
size=2 face=Arial>Jos</FONT></SPAN></DIV><BR>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> users-bounces@racket-lang.org
[mailto:users-bounces@racket-lang.org] <B>On Behalf Of </B>Maurizio
Giordano<BR><B>Sent:</B> miércoles, 13 de julio de 2011 23:31<BR><B>To:</B>
Matthias Felleisen<BR><B>Cc:</B> users<BR><B>Subject:</B> Re: [racket] Again on
bindings visibility in eval<BR></FONT><BR></DIV>
<DIV></DIV>Hi Matthias, hi all<BR><BR>
<DIV class=gmail_quote>2011/7/13 Matthias Felleisen <SPAN dir=ltr><<A
href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</A>></SPAN><BR>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote><BR><BR>[I hadn't forgotten your messages, it's just that
deadlines got in the way.]<BR><BR>I still don't understand your desire to
access the environmental variables specially:<BR><BR>1. if you generate
a closure or a struct full of closures in your macro, the expression that you
pass in captures the variables in its context:<BR><BR>> (define-syntax-rule
(mystuff y expr) (lambda (x) (displayln `(expr ,y)) (if expr x 0)))<BR>> [
(let ((t 333)) (mystuff t (> t 444))) 22]<BR>((> t 444)
333)<BR>0<BR><BR>See it really does get t's value from the
context.<BR><BR></BLOCKQUOTE>
<DIV>Yes it does ... I know that if the macro returns the lambda ...</DIV>
<DIV>no problem, unfortunately my macro returns something like:</DIV>
<DIV>(eval `(lambda ...))</DIV>
<DIV>Now the question is: Can I rewrite my macro to generate the same code</DIV>
<DIV>without using the "(eval `(lambda ...))"?</DIV>
<DIV>I don't know, I feel yes ... but at the moment I don't know how to</DIV>
<DIV>redesign it.</DIV>
<DIV>My lambda code is not a predefined template</DIV>
<DIV>(the quasiquote) with some small parts to be instantiated (with
unquoting).</DIV>
<DIV>First, the lambda code is very large,</DIV>
<DIV>Second, it is recursively produced by an expander function (used in the
macro).</DIV>
<DIV>When you call the macro, you don't know in advance how many
times </DIV>
<DIV>the expander will call itself. It is something like:</DIV>
<DIV><BR></DIV>
<DIV>(define-syntax-rule replace</DIV>
<DIV> ...</DIV>
<DIV> (eval `(lambda (x) </DIV>
<DIV> ... static
part ...</DIV>
<DIV> ,(expander
...) ; this inject a part of the lambda code </DIV>
<DIV> ...)))</DIV>
<DIV><BR></DIV>
<DIV>(define (expander ...)</DIV>
<DIV> `(let ((...))</DIV>
<DIV> ... static part ...</DIV>
<DIV> ,(expander ...)
; injection once again </DIV>
<DIV> ...))</DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote><BR>2a. do you have reason to access variables other than
throwing them into the environment for eval? In that case your problem is
solved.<BR> </BLOCKQUOTE>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>2b. if not, what are the reasons to guess at variable names
in the context of the macro USE (not definition)?<BR><BR></BLOCKQUOTE>
<DIV>I try to answer to both questions:</DIV>
<DIV><BR></DIV>
<DIV>My macro is the primitive of a new language:</DIV>
<DIV><BR></DIV>
<DIV>< elem1, elem2, ... , (replace x y by (+ x y) if (> x othervar))
></DIV>
<DIV><BR></DIV>
<DIV>the replace macro has the following inputs:</DIV>
<DIV>x, y = free variables to be matched on a set of elements
(<...>)</DIV>
<DIV>(+ x y) = a form to be inserted in the set inspite of x and y</DIV>
<DIV>(> x othervar) = a conditional form: here x is matched (bound)
locally,</DIV>
<DIV>othervar is a symbol "outside" the set (that is the scheme top env
or</DIV>
<DIV>any other inner env like a let)</DIV>
<DIV>This is why I need that the produced lambda USE outside symbols.</DIV>
<DIV>At the moment, in my implementation, the lambda can use outside</DIV>
<DIV>symbols if they are defined in the top env ... I would like to have it also
in</DIV>
<DIV>inner environments. </DIV>
<DIV> </DIV>
<DIV> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>;; ----------------<BR><BR><BR>SEPARATE QUESTION: Now you
also write that you process the code before you throw it to eval. Is it
possible to write functions on syntax that process the code and perform the
optimizations that Racket doesn't perform for you?<BR><FONT
color=#888888><BR></FONT></BLOCKQUOTE>
<DIV>That's an interesting question: yes ... I process A LOT the code
before</DIV>
<DIV>I throw it to the eval ... as I said you it is like a compiler (... my
first research area... many years ago!)</DIV>
<DIV>First: I generate recursively the code with a my expander function (not the
one of racket) </DIV>
<DIV>Second: I (try) to generate an efficient code to simulate the runtime of
the language (the chemical language) I have implemented on top of racket.</DIV>
<DIV>If you look at the generated code, you can figure out several
optimizations.</DIV>
<DIV>One is "inlining": if I have a lambda (in my case a chemical rule) that
will be executed many times (on all possible combinations of elements in a
set), </DIV>
<DIV>and each time the lambda may use recursion, than, from my experience it
is</DIV>
<DIV>better to explode recursive calls in recursive inlining of code.</DIV>
<DIV>From your question I understand that you mean "optimizations of
racket</DIV>
<DIV>code" that racket does not do.</DIV>
<DIV><BR></DIV>
<DIV>Absolutely an interesting discussion... thanks.</DIV>
<DIV><BR></DIV>
<DIV>Cheers,</DIV>
<DIV>Maurizio.</DIV>
<DIV> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote><FONT color=#888888>-- Matthias<BR></FONT>
<DIV>
<DIV></DIV>
<DIV class=h5><BR><BR><BR><BR><BR><BR>On Jul 13, 2011, at 3:54 PM, Maurizio
Giordano wrote:<BR><BR>> Hi all, hi Matthias,<BR>><BR>> I would like
to come back to my (still unsolved) problem I<BR>> proposed some days
ago:<BR>><BR>> when using define-syntax in a inner scope of bindings
(like let),<BR>> in this example:<BR>><BR>> (define-syntax
mymacro<BR>> (syntax-rules ()<BR>> [(_ x)<BR>>
(eval `(lambda (w) (print (quote x)) (if x w
#f)))]))<BR>><BR>> (let* ((s 3) (f (mymacro (> s 0)))) (f 5))<BR>>
reference to undefined identifier: s<BR>><BR>> of course if
you:<BR>><BR>> (define s 3)<BR>><BR>> in the top environment, the
error will not appear.<BR>> This is even more clear if you expand the
macro:<BR>><BR>> (syntax->datum (expand '(mymacro (> s
0))))<BR>> ... you see that "s" is a %top binding.<BR>><BR>> I know
that if I make the macro to return directly the lambda,<BR>> it works.
Nevertheless, in my implementation, I still need to use<BR>> the "(eval
(quasiquote (lambda ...)))".<BR>> Why? my macro is like a compiler<BR>>
that generates a lambda code very huge: the code is recursive in some of
its part,<BR>> but, for efficiency reasons, i preferred to inline all
recursive calls. So I use a<BR>> function "expander" that makes recursive
inlining (or injecting) of code).<BR>> It is more or less something
like:<BR>><BR>> `(lambda (...) ... static-code... ,(expander ...)
...)<BR>><BR>> where "expander call itself with different
parameters.<BR>><BR>> This is just to know your opinion... if the "(eval
(quasiquote (lambda ...)))"<BR>> cannot see local bindings like in let*,
than I have to choice:<BR>> 1) renounce to the feature.<BR>> 2) looking
for alternative methods to generate my code with recursive
inlining<BR>><BR>> Than you,<BR>> Cheers,<BR>>
Maurizio.<BR><BR></DIV></DIV></BLOCKQUOTE></DIV><BR></BODY></HTML>