Path: utzoo!utgpu!water!watmath!clyde!ima!johnl From: johnl@ima.ISC.COM (John R. Levine) Newsgroups: comp.lang.lisp Subject: Re: What's the value of lexical scoping Message-ID: <1046@ima.ISC.COM> Date: 4 Jun 88 21:26:59 GMT References: <24508@ucbvax.BERKELEY.EDU> <26500002@zaphod> Reply-To: johnl@ima.UUCP (John R. Levine) Organization: Not much Lines: 33 In article <26500002@zaphod> doug@zaphod.prime.com writes: > >First - I hope this actually makes it out. Most of my postings have stayed >local. > >The reasons for lexical scoping don't end with efficiency. It's true that >compiled code with lexical references is much more efficient then dynamically >scoped code but that isn't the whole story. > >The second good reason for lexical scoping is to solve the fexpr problem. >This is what happens when you get a collision between a parameter and >a global variable in dynamically scoped LISP. ... That's really a better reason. Every time I have used a dynamically scoped language (Lisp, APL, Snobol4) I have been bitten quite painfully by strange bugs due to unintended aliasing of names. In APL, many people treat the dynamic scoping effectively as a bug and create strange local variable names that are carefully intended not to collide with globals or names in other routines. I always had the impression that Lisp's dynamic scoping was an accidental effect of the a-list that Lisp 1.5 on the 7094 used to keep argument bindings. Then, like most accidental effects, people started taking advantage of it and it became enshrined in conventional use. The 1962 Lisp 1.5 manual notes that compiled functions have lexically bound variables (although like everthing else in the book, it is explained in a way that makes it almost incomprehensible) and explains how to make your function's variables special or common, so it seems reasonable to assume that from the first the semantics of the binding strategy were muddled. -- John R. Levine, IECC, PO Box 349, Cambridge MA 02238-0349, +1 617 492 3869 { ihnp4 | decvax | cbosgd | harvard | yale }!ima!johnl, Levine@YALE.something Rome fell, Babylon fell, Scarsdale will have its turn. -G. B. Shaw