

Lexical vs dynamic scoping in Lisp ... - RiderOfGiraffes

The first Lisp I ever used was LispKit.  Over one weekend I implemented the SECD engine in BCPL, then by hand compiled the LispKit definitions of eval and apply into SECD code and typed them in.  Hey Presto!  Running Lsip.<p>But LispKit Lisp used dynamic scoping.  If you have an unbound variable in an expression it uses the definition that was in force at the time of the call, not the definition that's in scope from the text of the surrounding code.  This was incredibly useful at times, but made debugging and analysis difficult.<p>To the best of my (very limited) knowledge, modern Lisps use lexical scoping.  Are there any current Lisps that use Dynamic scoping?<p>I could find that out for myself with a lot of searching and reading, but what I really want to know is this:<p>Do any of you use a system with dynamic scoping?
======
Jtsummers
Emacs Lisp uses dynamic scoping. Common Lisp uses lexical scoping by default,
but allows dynamic scoping.

~~~
RiderOfGiraffes
Thanks. Do you know of any detailed discussions of the pros and cons?

~~~
hga
I don't off hand, but for a start search on the upward funarg problem.

Here's the history as I learned it in the '80s (mostly):

Original Formula LISP as done by McCarthy was dynamically scoped for any one
of a number of reasons:

They didn't know better (this is 1958, when LISP was implemented as
subroutines callable from FORTRAN running on a vacuum tube IBM 704 and a lot
of it was based on a 1955-6 language).

They didn't know how to make it efficient, or I think especially interpreted
LISP, statically scoped when the latter became recognized as a big and/or the
right thing, largely due to Algol 60 (as in 1960). Among other things it's
memory hungry (see the Wikipedia Funarg problem article) and there just wasn't
much of that to go way back then. The 704 was IBM's first "core by default"
machine....

Scheme in 1975 was the first statically scoped LISP although the first
production quality version was T in the early '80s (and that was a necessary
proof of concept).

By the time of Common Lisp in 1984 it had long been recognized that default
dynamic scoping was ... not good, Common Lisp's change to default static was
perhaps its biggest breaking change and it was years before many code bases
were changed to it (by this time various LISP dialects were pretty mature and
there were some seriously useful systems written in them like Macsyma and the
Lisp Machine).

Since then, of all the Lisp dialects I consider to be "major", only Emacs Lisp
(ask RMS) and AutoLisp (AutoCad's extension language of 1986 based on "a very
early version of XLISP" the date of which I don't know, but XLISP proper
started in 1983) are dynamic by default. Everyone else has followed the lead
of Scheme and gone default static.

