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

From: maurizio.giorda (maurizio.giorda at gmail.com)
Date: Tue Jul 12 11:00:54 EDT 2011

>
> On Tue, Jul 12, 2011 at 4:36 PM, maurizio.giorda 
> <maurizio.giorda at gmail.com <mailto:maurizio.giorda at gmail.com>> wrote:
>
>     __
>     Hi Matthias,
>
>     ... I will play with your example (it is better than all the words
>     I spent with my looong
>     description:
>
>>     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!).
>
>
> Do you want a let* here instead of let?
Yes Markku,
you (and Matthias) are absolutely right... with let* works.
I did a mistake like a very beginner...

Nevertheless, now I have to re-formulate my macro.
I started from something like:

(define-syntax replace
    (syntax-rules (replace)
      [(replace input ...)
       (let* (...let-variables ...)
         (eval `(lambda (cntx)
                   ...  here unquote either let-variables and other 
utility functions...
                   ... maybe reference external variables...
               ))]))

What I do is simply to build the lambda code (with quasiquote  ... 
unquote ...).
The code is huge. It "replace" macro is some sort of compiler that 
generates the scheme code
for a new construct in a new language (a chemical language) implemented 
on top of racket.

Since Matthias suggested to avoid the (eval (quasiquote (lambda ...))) 
approach and replace it
with a (lambda ... (quasiquote ...)), now my work is trying to redesign 
my implementation.

Thank you,
Cheers,

Maurizio.


View Maurizio Giordano's profile on LinkedIn 
<http://it.linkedin.com/in/giordanomaurizio><http://it.linkedin.com/in/giordanomaurizio>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110712/fc91dbd2/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/fc91dbd2/attachment.png>

Posted on the users mailing list.