[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dynamic versus Lexical scoping
- To: clisp-list <firstname.lastname@example.org>
- Subject: Re: Dynamic versus Lexical scoping
- From: email@example.com (kr)
- Date: srialpop\r\e%, 27 May 1995 02:41:09 -0800
- Cc: <firstname.lastname@example.org>
At 6:09 5/27/95, Jean-Paul Tea wrote:
>My question is:
>What is dynamic or lexical scoping? What are the advantages and
>disadvantages of each?
All the old, historic implementations used dynamic scoping, but it turns
out that this provides many opportunities for subtle bugs, which are
difficult to understand and track down. That is because the behaviour of
the program is not directly understandable by merely reading the lexical
(textual) representation of the source code. That's why lexical scoping has
been finally adopted by Scheme, and subsequently Common LISP, today's
dominating standard. But one the of bigger LISPs, Interlisp from Xerox
PARC, has been using dynamic scoping, as does Emacs LISP. These seem to be
relics from the past. :-)
Lexical scoping is familiar from languages such as Pascal and C, which
never had the concept of dynamic scoping. In Common LISP, special variables
can be used for dynamic scoping, but it should be used with a lot of
thought and care.
>I try reading it in books, but they are so vague on the subject.
The books on the history of LISP often discuss the distinction, and the
problems with dynamic scoping. In current-day books, it is just assumed
that Common LISP with static scoping is the default.
There is a concise discussion of the distinction and of some of the
advantages of using dynamic scoping for selected tasks, and how to
implement a similar effect within a static framework, on p.319-324 of the
excellent book "Structure and Interpretation of Computer Programs", by
Abelson and Sussman (MIT Press 1985), which is a classic book, using Scheme
as a language.