[CM] scoping in scheme
Orm Finnendahl
finnendahl@folkwang-hochschule.de
Wed, 29 Oct 2003 21:40:16 +0100
Hi,
hope this is not too off topic: Is it possible to define a top-level
closure in scheme which acesses (and changes) variables from the
dynamically scoped environment it is called in?
In the following example i is bound at define time and its value in a
function call is always taken from the definition's lexical context:
(define test-proc
(lambda ()
(set! i (+ i 2))))
(list
(begin
(define i -3)
(let ((i 1))
(test-proc)
i
)
)
i)
=> (1 -1)
It would be nice if the result could be made to be (3 -3) without
having to supply i as arguments to test-func. Test-func is only
evaluated for its side effects which should affect the variable's
meanings in the current dynamic context of the function call.
It might be either trivial or the wrong way to go about the whole
thing but I thought I'd ask anyway.
Any ideas?
Orm