From: Alan L. Batongbacal
Subject: Question about dynamic scoping
Date: 
Message-ID: <1881@creatures.cs.vt.edu>
Hi there!  I'm working on a project using Austin-Kyoto Common Lisp for
the NeXT.

I'm wondering whether that dialect supports dynamic scoping (the docs
I have aren't clear).  Specifically, I want something like the
following:

(defun f1 (var1)
	(f2 10))

(defun f2 (x)
	(+ var1 x))

(f1 5)
-->15

I tried this out and it didn't work--"variable VAR1 unbound", it said.
I also tried it on Allegro Common Lisp under ULTRIX 4.2, and got the same
results.

Is there some toggle I have to set, or something else I have to do?
Thanks!

-alan
·······@csgrad.cs.vt.edu

From: Christopher Lusardi
Subject: Re: Question about dynamic scoping
Date: 
Message-ID: <1991Nov14.224711.7859@acsu.buffalo.edu>
In article <····@creatures.cs.vt.edu> ······@thorcs.vt.edu (Alan L. Batongbacal) writes:
>Hi there!  I'm working on a project using Austin-Kyoto Common Lisp for
>the NeXT.
>
>I'm wondering whether that dialect supports dynamic scoping (the docs
>I have aren't clear).  Specifically, I want something like the
>following:
>
>(defun f1 (var1)
>	(f2 10))
>
>(defun f2 (x)
>	(+ var1 x))
>
>(f1 5)
>-->15
>
>I tried this out and it didn't work--"variable VAR1 unbound", it said.
>I also tried it on Allegro Common Lisp under ULTRIX 4.2, and got the same
>results.
>
>Is there some toggle I have to set, or something else I have to do?
>Thanks!
>
>-alan
>·······@csgrad.cs.vt.edu

Common lisp uses static scope. All other lisps uses dynamic scope.
If you use global variable in Common Lisp then it's like Pascal,
Modula II, C, Ada etc.

-- 
Christopher M. Lusardi     University At Buffalo     ·······@acsu.buffalo.edu
From: John Gateley
Subject: Re: Question about dynamic scoping
Date: 
Message-ID: <GATELEY.91Nov14175322@gefion.rice.edu>
In article <·····················@acsu.buffalo.edu> ·······@acsu.buffalo.edu (Christopher Lusardi) writes:

   Common lisp uses static scope. All other lisps uses dynamic scope.

First, Common Lisp provides both lexical and dynamic scoping -- check
out the SPECIAL argument to DECLARE. Second, all other lisps do not
use dynamic scoping. Most (if not all) modern lisps, such as CL,
Scheme, and T, use lexical scoping (in CL, as the default). The
earlier lisps did primarily use dynamic scoping, but this is no longer
true.

j
--
·······@rice.edu
Si pots llegir aquest, m'agrada si contestara`s.
From: Bob Kerns
Subject: Re: Question about dynamic scoping
Date: 
Message-ID: <1991Nov15.040510.29992@crl.dec.com>
In article <·····················@acsu.buffalo.edu>, ·······@acsu.buffalo.edu (Christopher Lusardi) writes:
> Common lisp uses static scope. All other lisps uses dynamic scope.

Untrue!  VERY untrue.

Even if you got it right, it's a singularly unhelpful answer.

First, the term is "lexical scope", not "static scope".

Secondly, your characterization of "all other lisps" is wildly
inaccurate.  SOME other lisps (for example, gnuemacs' lisp,
or interpreted MacLisp) use dynamic scoping.  Others, like
Scheme, NIL, Zetalisp use lexical scoping.

> If you use global variable in Common Lisp then it's like Pascal,
> Modula II, C, Ada etc.

Well, if you mean DEFVAR, then this is true.

Unfortunately, I don't have time tonight to write an explanation
of scoping in Lisp.  I WILL suggest that Alan should go out and
buy himself a copy of "Common Lisp the Language, Second edition",
by Guy L. Steele.  Since this is a reference book (although pretty
readable), he probably should also get a good Lisp textbook, but
I'm afraid I don't know what to recommend.  It is quite possible
that his problem is that he is working from a *BAD* textbook, or
even worse, a VERY OBSOLETE one, like say, the Little Lisper.
From: Jeff Dalton
Subject: Re: Question about dynamic scoping
Date: 
Message-ID: <5646@skye.ed.ac.uk>
In article <······················@crl.dec.com> ···@crl.dec.com (Bob Kerns) writes:
>In article <·····················@acsu.buffalo.edu>, ·······@acsu.buffalo.edu (Christopher Lusardi) writes:
>> Common lisp uses static scope. All other lisps uses dynamic scope.

>First, the term is "lexical scope", not "static scope".

I don't like to disagree with RWK, because in most cases it would
mean I'd be wrong, but in this case I think some minor clarifications
may be helpful.

Lexical and static scope are often used interchangeably.  I'm not
sure which, if either, is more correct.  However, "staic scope" is
sometimes used for Lisp.  For example, the introduction to the
Revised Report on Scheme says:

   Scheme was one of the first programming languages to incorporate
   first-class procedures as in the lambda calculus, thereby proving
   the usefulness of static scope rules and block structure in a
   dynamically typed language.

>Secondly, your characterization of "all other lisps" is wildly
>inaccurate.  SOME other lisps (for example, gnuemacs' lisp,
>or interpreted MacLisp) use dynamic scoping.  Others, like
>Scheme, NIL, Zetalisp use lexical scoping.

This is an important point, and it's possible to make it stronger.
In Lisps such as MacLisp, the interpreter used dynamic scoping but
the compiler used lexical scoping by default.  (This is true even
though the bindings didn't have indefinite extent and even though
lambda-expressions other than in the car position were treated
in effect as separate functions.  If you bound a variable V in a
function F, V would not be visible to functions that F called
unless V was declared special.)

Moreover, many programmers regarded the compiler's semantics as
the true semantics.

That's one tradition within Lisp.  Another, associated with dialects
such as Interlisp, is to regard the interpreter's semantics as the
true semantics and have dynamic scoping as the default in compiled
code as well as interpreted.

>> If you use global variable in Common Lisp then it's like Pascal,
>> Modula II, C, Ada etc.
>
>Well, if you mean DEFVAR, then this is true.

Global variables in Common Lisp are special variables, and it
is possible to write code that notices this.  So they aren't
exactly the same as lexically scoped global variables.

Moreover, DEFVAR proclaims the variable special.  So if you
write (DEFVAR V 10), V will be considered a special variable
throughout the rest of the program.

(I don't mean to imply that RWK doesn't know these things,
at least not in the cases where I've said something that's
true.)

>Unfortunately, I don't have time tonight to write an explanation
>of scoping in Lisp.  I WILL suggest that Alan should go out and
>buy himself a copy of "Common Lisp the Language, Second edition",
>by Guy L. Steele.  Since this is a reference book (although pretty
>readable), he probably should also get a good Lisp textbook, but
>I'm afraid I don't know what to recommend.  It is quite possible
>that his problem is that he is working from a *BAD* textbook, or
>even worse, a VERY OBSOLETE one, like say, the Little Lisper.

The current edition of the Little Lisper uses Scheme and hence
(I'm pretty sure) lexical scoping.

I'd second the recommendation of CLtL II.  The 2nd edition
of Touretzky's Gentle Introduction (the edition that uses
Common Lisp) is pretty good.  And there's always Winston 
and Horn (3rd edition).  Abelson and Sussman^2's _Structure
and Interpretation of Computer Programs_ is excellent and
will also tell you about lexical and dynamic scoping.

-- jd
From: John Lacey
Subject: Re: Question about dynamic scoping
Date: 
Message-ID: <johnl.690706737@copper>
····@aiai.ed.ac.uk (Jeff Dalton) writes:

>In article <······················@crl.dec.com> ···@crl.dec.com (Bob Kerns) writes:

>>I'm afraid I don't know what to recommend.  It is quite possible
>>that his problem is that he is working from a *BAD* textbook, or
>>even worse, a VERY OBSOLETE one, like say, the Little Lisper.

>The current edition of the Little Lisper uses Scheme and hence
>(I'm pretty sure) lexical scoping.

Sigh.  The Little LISPer is *far* from obsolete, and is now in it's
3rd edition (1989).  Also, it *does not use Scheme*!  It uses a very
simple lisp for its own pedagogical purposes.  Fortunately, this lisp
quite closely resembles both Scheme and Common Lisp. (The text
contains notes on where changes to adapt the text to one of these
languages are necessary.)

In case it isn't obvious from the above, the Little LISPer uses
lexical scoping.

(Sorry, but I'm at Indiana, and I can't let this slip by.  On the
other hand, I could get roasted if anyone here found out I was reading
this newsgroup. :-)

>I'd second the recommendation of CLtL II.

I'll third this.

--
John Lacey, ·····@copper.ucs.indiana.edu                    ---Animal Logic
"Fragile as a kitten, strong as an ox, slow as a turtle, and sly as a fox."