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!

On Sat, Jan 31, 2009 at 5:11 PM, Marc Feeley <feeley@iro.umontreal.ca> wrote:

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)

This is the way you can do dynamic scoping in Gambit (and other Schemes too):

(define foo (make-parameter (lambda (x) (* x 2))))


(define (g x) ((foo) x))

(pp (list (g 1) (parameterize ((foo (lambda (x) (* x 3)))) (g 1))))

You can also use dynamic-wind to simulate dynamic scoping but it does not work properly with threads.

Marc