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

From: Maurizio Giordano GMAIL (maurizio.giorda at gmail.com)
Date: Mon Jul 11 11:04:24 EDT 2011

On Mon, 2011-07-11 at 13:43 +0100, Noel Welsh wrote:
> On Mon, Jul 11, 2011 at 1:26 PM, Maurizio Giordano GMAIL
> <maurizio.giorda at gmail.com> wrote:
> > PS. my lambda is generated by a macro (define-syntax) ...
> > this is why I use eval to generate the corresponding procedure.
> If this is the case I don't think you need to use eval. You either
> need to write your macro in a hygenic way -- it accepts as parameters
> all the identifiers in the enclosing environment that is should
> reference -- or you should explicitly break hygiene. If you're new-ish
> to Racket the preceeding sentence probably won't make any sense, so
> feel free to ask for more help!
> Cheers,
> N.

Hi Nole,
Yes, I am an absolute new-ish to racket... I would like to know more
about writing a macro by "explicitly break hygiene". 
I supposed I didn't need to use eval... but for me it is 
the easiest way to "build" a lambda-code and then evaluate it.

I want to give you more details about my problem.
I have a macro like this:

(define-syntax mymacro
  (syntax-rules (mymacro)
    [(mymacro input ...)
     (let* (...)
       (eval `(lambda (cntx) 
                 ...      ; a code generated according to macro
"input ..."
                 (+ x 2)  ; that contains references to an outside "x"

Note that I cannot foresee which extern symbols are referenced by the 
generated lambda.
This macro returns a procedure.
if I use my macro in a "let" construct, of course I have a "reference to
an undefined identifier":  

(let* ((x 1) 
       (f (mymacro ...)))
     (f 2))
reference to undefined identifier: x

So, coming back to my question: since the eval is called within the
scope, is it possible to make it aware of the bindings of the "let"? 
Do you know alternative mechanism to do that?



Posted on the users mailing list.