From: John L. Stein
Subject: Is dynamic scoping possible in scheme ?
Date: 
Message-ID: <5c6fv8$12hg@uni.library.ucla.edu>
STk> (define (bit x y)
    (let () 
      (set! x 1)
      (set! y zz) y))
#[undefined]
STk> (define (blob zz)
  (bit x y))
#[undefined]
STk> (blob 7)

*** Error:
unbound variable: zz


This should work according to my lisp book.
I think this is dynamic scoping

But it doesn't work on my version of schem STk.
Maybe dynamic scoping is forbidden in scheme.
Any help greatly appreciated.

Thanks
-js

From: Will Hartung
Subject: Re: Is dynamic scoping possible in scheme ?
Date: 
Message-ID: <vfr750E4H689.CDF@netcom.com>
(3 posts from John later --- :-)
"John L. Stein" <·····@seas.ucla.edu> writes:

>STk> (define (bit x y)
>    (let () 
>      (set! x 1)
>      (set! y zz) y))
>#[undefined]
>STk> (define (blob zz)
>  (bit x y))
>#[undefined]
>STk> (blob 7)

>*** Error:
>unbound variable: zz


>This should work according to my lisp book.
>I think this is dynamic scoping

Yup! It is dynamic scoping, and you must be using an OLD Lisp/Lisp book.
Modern Common Lisp doesn't use dynamic scoping any longer. 

>But it doesn't work on my version of schem STk.
>Maybe dynamic scoping is forbidden in scheme.
>Any help greatly appreciated.

Scheme has never supported dynamic scoping. As a late comer to the
Lisp/Scheme world, I've yet to want to use dynamic scoping, and it is
my understanding that its use could introduce some truly scary bugs.
So, I'm pretty happy that we don't get to use it any longer.

Hope this helps.

-- 
Will Hartung - Rancho Santa Margarita. It's a dry heat. ······@netcom.com
1990 VFR750 - VFR=Very Red    "Ho, HaHa, Dodge, Parry, Spin, HA! THRUST!"
1993 Explorer - Cage? Hell, it's a prison.                    -D. Duck
From: Thomas A. Russ
Subject: Re: Is dynamic scoping possible in scheme ?
Date: 
Message-ID: <ymik9p3m65b.fsf@hobbes.isi.edu>
In article <··········@gremlin.nrtc.northrop.com> ········@shomase.NoSubdomain.NoDomain (Jeff Barnett) writes:

 > In article <················@netcom.com>, ······@netcom.com (Will Hartung) writes:
 > |> (3 posts from John later --- :-)
 > |> "John L. Stein" <·····@seas.ucla.edu> writes:
 > 
 > |> Modern Common Lisp doesn't use dynamic scoping any longer. 
 > 
 > Wrong.  Both lexical and dynamic scoping are available.  Up
 > to about 1965, the default in most Lisps that had both was
 > dynamic.  Past that time, the default changed to lexical
 > mainly because of run-time efficiency.

Another important consideration was that lexical scoping makes the code
easier to understand, since all variable bindings can be found simply by
looking at the function definition.  Dynamic scoping requires knowledge
of the call tree to find variable bindings, so it is a much more tedious
process.



-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Jeff Barnett
Subject: Re: Is dynamic scoping possible in scheme ?
Date: 
Message-ID: <E4HM8o.5A2@gremlin.nrtc.northrop.com>
In article <················@netcom.com>, ······@netcom.com (Will Hartung) writes:
|> (3 posts from John later --- :-)
|> "John L. Stein" <·····@seas.ucla.edu> writes:

|> Modern Common Lisp doesn't use dynamic scoping any longer. 

Wrong.  Both lexical and dynamic scoping are available.  Up
to about 1965, the default in most Lisps that had both was
dynamic.  Past that time, the default changed to lexical
mainly because of run-time efficiency.  It was much latter,
circa the discussion on Common Lisp, that lexical scoping
meant closures.  In any event, Common Lisp has both but,
since dynamic isn't the default, you the user must whisper
something to the compiler/eval to let it know your intentions.
The way to communicate is with a SPECIAL declaration or
proclimation of the use of DEF{VAR|CONSTANT|PARAMETER}.

Jeff Barnett
From: Erik Naggum
Subject: Re: Is dynamic scoping possible in scheme ?
Date: 
Message-ID: <3063055724135671@naggum.no>
* Will Hartung
| Modern Common Lisp doesn't use dynamic scoping any longer. 

yes, it does.  however, the default is lexical scope, and you have to
request dynamic scope specially.

certain variables in Common Lisp are defined as dynamic (special) by the
standard, such as the *package*, *read-base*, *print-base*, just to name
three that are very frequently referenced while reading and printing.

#\Erik
-- 
1,3,7-trimethylxanthine -- a basic ingredient in quality software.
From: Chris Bitmead
Subject: Re: Is dynamic scoping possible in scheme ?
Date: 
Message-ID: <BITMEADC.97Feb5115909@Alcatel.com.au>
In article <················@naggum.no> Erik Naggum <····@naggum.no> writes:

>* Will Hartung
>| Modern Common Lisp doesn't use dynamic scoping any longer. 
>
>yes, it does.  however, the default is lexical scope, and you have to
>request dynamic scope specially.
>
>certain variables in Common Lisp are defined as dynamic (special) by the
>standard, such as the *package*, *read-base*, *print-base*, just to name
>three that are very frequently referenced while reading and printing.

Of course you could write your own dynamic scoping pretty easily in
Scheme. Make all your dynamic variables global and then write a macro
let-dynamic which saves the old value, and then resets it afterwards.