[racket] help: how to make eval see local bindings?

From: maurizio.giorda (maurizio.giorda at gmail.com)
Date: Tue Jul 12 09:36:06 EDT 2011

Hi Matthias,

... I will play with your example (it is better than all the words I 
spent with my looong
> Here is what I meant:
> #lang racket
> (define-syntax-rule
>   (mm x)
>   (lambda (w) (displayln `(,x)) (+ w x)))
Ok, fine!
> (define f
>   (let ([a 10])
>     (mm a)))
> (f 42)
Let me define my function in a inner scope:

 > (let ((othervar 2)
           (f (mm (+ 1 othervar))))
 >  (f 1)

it should print 4 but it gives the undefined identifier error.
If I define "othervar" globally (top env) it works (of course!).

 > (define othervar 2)
 >  (let ((f (mm (+ 1 othervar))))
         (f 1)
it prints 4.

If you ask me why I need to call "mm" with an expression, instead of a 
value... like: (mm (+ 1 othervar))
The answer is: my macro "replace" is a constructor of a function... I 
would like that this
function could reference external variables (not passed by parameters): 
if the reference
extern variable is defined (in the current scope) its value is used, 
otherwise the function
must give the "undefined identifier error".
The function I refer to is a "chemical reaction function": it applies to 
chemical molecules
(the macro parameters) but it can use reference to external variables to 
fire or not the
reaction. Example

(replace x y by x if (> x top)) -> #<procedure>

says: replace any pair of two molecules (x and y) with only one of them if
the value of the first is not greater than "top".



View Maurizio Giordano's profile on LinkedIn 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110712/54296444/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: btn_viewmy_160x25.png
Type: image/png
Size: 1208 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20110712/54296444/attachment.png>

Posted on the users mailing list.