[racket] Again on bindings visibility in eval

From: Maurizio Giordano (maurizio.giorda at gmail.com)
Date: Wed Jul 13 15:54:46 EDT 2011

Hi all, hi Matthias,

I would like to come back to my (still unsolved) problem I
proposed some days ago:

when using define-syntax in a inner scope of bindings (like let),
in this example:

(define-syntax mymacro
  (syntax-rules ()
    [(_ x)
      (eval `(lambda (w) (print (quote x)) (if x w #f)))]))

(let* ((s 3) (f (mymacro (> s 0)))) (f 5))
reference to undefined identifier: s

of course if you:

(define s 3)

in the top environment, the error will not appear.
This is even more clear if you expand the macro:

(syntax->datum (expand '(mymacro (> s 0))))
... you see that "s" is a %top binding.

I know that if I make the macro to return directly the lambda,
it works. Nevertheless, in my implementation, I still need to use
the "(eval (quasiquote (lambda ...)))".
Why? my macro is like a compiler
that generates a lambda code very huge: the code  is recursive in some of
its part,
but, for efficiency reasons, i preferred to inline all recursive calls. So I
use a
function "expander" that makes recursive inlining (or injecting) of code).
It is more or less something like:

`(lambda (...) ... static-code...  ,(expander ...) ...)

where "expander call itself with different parameters.

This is just to know your opinion... if the "(eval (quasiquote (lambda
...)))"
cannot see local bindings like in let*, than I have to choice:
1) renounce to the feature.
2) looking for alternative methods to generate my code with recursive
inlining

Than you,
Cheers,
Maurizio.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110713/6cd160c5/attachment.html>

Posted on the users mailing list.