[gambit-list] dynamic scope
lowlycoder at huoyanjinjing.com
Sat Jan 31 21:05:20 EST 2009
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
On Sat, Jan 31, 2009 at 5:11 PM, Marc Feeley <feeley at 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
> (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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gambit-list