Cool, thanks!<br><br>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:<br><br>I'm looking at an existing code base, it has 'foo', which depends on 'bar'.<br>
<br>I want to call existing function 'foo' with a new definition of 'bar'.<br><br>Is there no other way than to edit the definition of bar and make it a parameter?<br><br>Thanks!<br><br><div class="gmail_quote">
On Sat, Jan 31, 2009 at 5:11 PM, Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca">feeley@iro.umontreal.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c"><br>
On 31-Jan-09, at 7:49 PM, lowly coder wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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:<br>
<br>
(define (foo x) (* x 2))<br>
<br>
(define (g x) (foo x))<br>
<br>
(pp (list (g 1) (dynamic-let ( (foo (lambda (x) (* x 3)))) (g 1))))<br>
<br>
to get me:<br>
<br>
(2 3)<br>
</blockquote>
<br></div></div>
This is the way you can do dynamic scoping in Gambit (and other Schemes too):<br>
<br>
(define foo (make-parameter (lambda (x) (* x 2))))<div class="Ih2E3d"><br>
<br>
(define (g x) ((foo) x))<br>
<br></div>
(pp (list (g 1) (parameterize ((foo (lambda (x) (* x 3)))) (g 1))))<br>
<br>
You can also use dynamic-wind to simulate dynamic scoping but it does not work properly with threads.<br><font color="#888888">
<br>
Marc<br>
<br>
</font></blockquote></div><br>