Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-unix!hplabs!tektronix!tekcrl!tekchips!willc From: willc@tekchips.UUCP (Will Clinger) Newsgroups: comp.lang.lisp Subject: Re: A small brush fire ... Message-ID: <869@tekchips.UUCP> Date: Tue, 25-Nov-86 17:50:23 EST Article-I.D.: tekchips.869 Posted: Tue Nov 25 17:50:23 1986 Date-Received: Wed, 26-Nov-86 09:49:08 EST References: <412@ethz.UUCP> Reply-To: willc@tekchips.UUCP (Will Clinger) Organization: Tektronix, Inc., Beaverton, OR. Lines: 60 In article <412@ethz.UUCP> ceb@ethz.UUCP (Charles Buckley) writes: >The code presented certainly depends on the scoping rules, but the >second part of the challenge remains unanswered, i. e. "can't be coded >AS WELL in a way that doesn't depend on the scoping rules." > >In fact, in the context of the (perforce) interpreted >lambda-expression which makes up the function pased as an argument, >list is a special variable which must be resolved by name at runtime, >an expensive process. Therefore, many would not consider the above an >example of good code at all. Mr Buckley misses the point. The lambda expression is interpreted only because it was quoted. I assume Mr Steele used the quote only to force dynamic scope rules to be used for testing, and that he forgot to remove the quote after testing. Mr Steele's point was that dynamic scope rules would make it impossible to write MYMAPCAR in such a way that it is independent of the names of variables bound in code that calls it. Mr Buckley continues: >One rule independent way of coding the above (I use Zetalisp syntax) is > >(defun mynewmapcar (function list-to-be-indexed &rest fixed-args) > (cond ((null list-to-be-indexed) nil) > (t (cons (lexpr-funcall function (car list-to-be-indexed) fixed-args) > (lexpr-funcall 'mynewmapcar function (cdr list-to-be-indexed) > fixed-args))))) This code is *not* independent of the scope rules. It will not work correctly if dynamic scope rules are used and CONSALL is defined by (defun consall (l list-to-be-indexed) (mynewmapcar 'cons l list-to-be-indexed)) If dynamic scope rules are used, it is simply impossible to write such procedures that will not break when called from code written by other programmers who have been unlucky in their choice of variable names. (Well, not quite impossible. I once got so fed up with this problem in MacLisp that I wrote a macro that took a DEFUN and substituted the bound variable names by gensyms throughout the DEFUN. But it's pretty crummy to have to resort to such lousy hacks.) For the benefit of people who don't speak Zetalisp, Mr Buckley's example would appear in Scheme as: (define (mynewmapcar function list-to-be-indexed . fixed-args) (cond ((null? list-to-be-indexed) '()) (else (cons (apply function (car list-to-be-indexed) fixed-args) (apply mynewmapcar function (cdr list-to-be-indexed) fixed-args))))) Syntax and typos aside, the only difference between Mr Buckley's example and Mr Steele's example is that Mr Buckley extended MYNEWMAPCAR to take more than two arguments. William Clinger Tektronix Computer Research Laboratory