
"KPY" == Ka-Ping Yee <ping@lfw.org> writes:
KPY> On Thu, 22 Feb 2001, Jeremy Hylton wrote:
I can't think of another lexically scoped language that allows an exec or eval to create a new variable binding that can later be used via a plain-old reference.
KPY> I tried STk Scheme, guile, and elisp, and they all do this. I guess I'm just dense then. Can you show me an example? The only way to introduce a new name in Scheme is to use lambda or define which can always be translated into an equivalent letrec. The name binding is then visible only inside the body of the lambda. As a result, I don't see how eval can introduce a new name into a scope. The Python example I was thinking of is: def f(): exec "y=2" return y
f() 2
What would the Scheme equivalent be? The closest analog I can think of is (define (f) (eval "(define y 2)") y) The result here is undefined because y is not bound in the body of f, regardless of the eval. Jeremy