Ludovic Court?s:
"Maciek Godek" <[EMAIL PROTECTED]> writes:
I've been wondering if there's any way to recall
(or get inside) an environment of a closure (= to
directly access variables bound to a closure)
Yes, with `the-environment':
guile> ((lambda (a b) (the-environment)) 2 3)
(((a b) 2 3) #<eval-closure b7c6dcf8>)
But don't do that, since the representation of environments could
eventually change.
Please don't change it. :-)
It's one of those things which makes Guile special.
Maciek Godek:
Don't worry, I won't :)
Now I only know how to obtain environment of a closure,
but I still don't know how to get inside and modify it (I'm
lacking this `with' I wrote about).
The function "local-eval" is probably what you want.
I use local-eval a lot, it's one of the really really
nice features provided by Guile:
(define-macro (with env . code)
`(local-eval (quote (begin ,@code)) ,env))
(define ++
(let ((c 0))
(c-display "env" (the-environment))
(lambda()
(set! c (1+ c)) c)))
(++)
=> 1
(with (procedure-environment ++) (set! c 20))
(++)
=> 20