Cool, thanks!
The 'problem' I see with this, is that I have to know before hand that I want this variable to be dynamic. The use case here is:
I'm looking at an existing code base, it has 'foo', which depends on 'bar'.
I want to call existing function 'foo' with a new definition of 'bar'.
Is there no other way than to edit the definition of bar and make it a parameter?
Thanks!
This is the way you can do dynamic scoping in Gambit (and other Schemes too):
On 31-Jan-09, at 7:49 PM, lowly coder wrote:
is there anyway i can obtain dynamic scoping in gambit? lexically scoping is really cool, and I want it as the default behavior; i just want the ability to go:
(define (foo x) (* x 2))
(define (g x) (foo x))
(pp (list (g 1) (dynamic-let ( (foo (lambda (x) (* x 3)))) (g 1))))
to get me:
(2 3)
(define foo (make-parameter (lambda (x) (* x 2))))(pp (list (g 1) (parameterize ((foo (lambda (x) (* x 3)))) (g 1))))
(define (g x) ((foo) x))
You can also use dynamic-wind to simulate dynamic scoping but it does not work properly with threads.
Marc