[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Lexically vs. Dynamically scoped Lisps.
- To: narain@rand-unix
- Subject: Re: Lexically vs. Dynamically scoped Lisps.
- From: Eduardo Krell <ekrell@UCLA-LOCUS>
- Date: Tue ,13 Nov 84 13:54:43 EDT
- Cc: t-discussion@YALE.ARPA
- In-reply-to: Your message of 10 Nov 84 21:48:41 PST (Sat).
There are some clear advantages to lexical scoping. To illustrate this,
let's assume for a moment that Pascal has dynamic scoping. Consider the
following piece of program:
var t : integer;
...
t := 1;
...
procedure P;
begin
... t ...
end;
The person who wrote this program intended that the t referenced from
within procedure P be the one declared just above. However, since the
language has dynamic scoping, if t is redeclared prior to calling P:
var t : integer;
...
t := 5;
P;
then that instance of t will be used in P. This is very annoying,
since the original writer probably didn't intend this effect.
Another clear advantage of lexical scoping is compilation. Let's use
the same piece of program. If the language is lexically scoped, then
the reference to t in P can be translated (at compile time) to a
particular address (the t declared just before P) regardless of the
value of t in effect when a call to P is made.
If the language was dynamically scoped, then the reference to t
in P can not be translated into one address, since the t used will be
the one visible at the point P is called. Therefore, if you have several
calls to P with several redeclarations of t, you will be, in effect,
using different values of t at different calls to P.
I hope this clarifies your question.