Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!styx!ames!ucbcad!ucbvax!decvax!mcnc!unc!steele From: steele@unc.UUCP (Oliver Steele) Newsgroups: comp.lang.lisp Subject: Re: A small brush fire ... Message-ID: <269@unc.unc.UUCP> Date: Thu, 20-Nov-86 18:16:42 EST Article-I.D.: unc.269 Posted: Thu Nov 20 18:16:42 1986 Date-Received: Fri, 21-Nov-86 20:30:15 EST References: <8868@duke.duke.UUCP> Reply-To: steele@unc.UUCP (Oliver Steele) Organization: CS Dept, U. of N. Carolina, Chapel Hill Lines: 46 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 (defun mymapcar (myfunction list) (cond ((null list) nil) (t (cons (myfunction (car list)) ;or funcall, etc. (mymapcar myfunction (cdr list)))))) (defun consall (l list) (mymapcar '(lambda (x) (cons x list)) l)) lexical: (consall '(a b c) '(d)) ==> ((a d) (b d) (c d)) dynamic: (consall '(a b c) '(d)) ==> ((a a b c) (b b c) (c c)) The problem isn't so much that you don't get what you expected with dynamic scoping, but that what you get depends on the lambda variables used in the function you're calling. This is the same problem as using global variables: you have to know what variables the procedures you're calling use, instead of just what they do. e.g.: (defun consall2 (l llist) (mymapcar '(lambda (x) (cons x llist)) l)) ought to do the same thing as consall, but will give different results under dynamic scoping. -- Oliver Steele----------------------------------steele@unc When a tree dies, ...!{decvax,ihnp4}!mcnc!unc!steele plant another in its place. steele%unc@csnet-relay.csnet