Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!enea!zyx!bd From: bd@zyx.UUCP (Bjorn Danielsson) Newsgroups: comp.lang.lisp Subject: Re: A small brush fire ... Message-ID: <217@zyx.UUCP> Date: Wed, 26-Nov-86 19:25:53 EST Article-I.D.: zyx.217 Posted: Wed Nov 26 19:25:53 1986 Date-Received: Thu, 27-Nov-86 02:01:09 EST References: <8868@duke.duke.UUCP> Reply-To: bd@zyx.UUCP (Bjorn Danielsson) Organization: ZYX AB, Stockholm, Sweden Lines: 32 In article <8868@duke.duke.UUCP> jds@duke.UUCP (Joseph D. Sloan) writes: > > So how would you answer the following: Since "good" >programmers know better than using free (== global) variables, >the argument between lexical and dynamic scoping is really a >mute point. The real issue this: Can you exhibit a piece of code >that depends on the scoping rules that can't be coded AS WELL >in a way that doesn't depend on the scoping rules? > > duke!jds Dynamic scoping is quite useful in code like: (let ((*print-base* 2)) (print (stuff))) Or in general, when the dynamic binding of a global variable is used to pass a parameter to another function (in this case "print", or some function called by print), but the variable is never accessed locally. In most other cases where free variables occur, you should use closures: (defun consall (l list) (mymapcar (function (lambda (x) (cons x list))) l)) Because the closure is created when the dynamically visible variable "list" is the same as the lexically visible one, the difference between the two kinds of scoping disappear. -- Bjorn Danielsson, ZYX, +46 8 653205, ...mcvax!enea!zyx!bd