On 5/6/07, Chicken Monk <[EMAIL PROTECTED]> wrote:
Hi,I noticed that the following doesn't work in Chicken: (define a 42) (define (foo b) (let ((c (+ b 1))) (let ((env (interaction-environment))) (eval '(+ a b c) env)))) ; doesn't work with or without the env. (print (foo 3)) Error: unbound variable: b I would expect eval to "know" about b and c as well. The manual, however, points out that it uses (interactive-environment) by default. A few questions: 1. Why is (interactive-environment) the default? (Or, why doesn't eval have access to all the variables that "regular" code would have?)
It does, but only to global variables.
2. Is it possible to get the "local environment" (which should have access to b and c)? Is there even such a thing, or am I seeing this completely wrong?
This is not possible in general, unless you really want to peek into the internal representation of a closure.
3. Are there other ways to make this work? I am aware of the environments egg, but having to manually add values to an environment does not sound very appealing. :-(
That's understandable, but the environments egg is generally intended to handle custom environments for top-level variables (and that only in interpreted code).
Of course, it's possible that I completely misunderstand the subject, in which case I would love to be enlightened. :-)
Well, actually it would be mightily handy! See for example: http://www.bcl.hamilton.ie/~qobi/map-closure/ But the implementation of such a facility severely constrains the implementation, and thus is quite expensive (I believe, but who knows - people said this of continuations, once...) cheers, felix _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
