Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!seismo!lll-crg!lll-lcc!vecpyr!amd!pesnta!hplabs!tektronix!tekcrl!tekchips!willc From: willc@tekchips.UUCP (Will Clinger) Newsgroups: net.lang.lisp Subject: Re: Abusing "define" in Scheme... (car crashes?) Message-ID: <328@tekchips.UUCP> Date: Fri, 23-May-86 14:05:52 EDT Article-I.D.: tekchips.328 Posted: Fri May 23 14:05:52 1986 Date-Received: Thu, 29-May-86 02:31:07 EDT References: <13508@ucla-cs.ARPA> <2048@mit-eddie.MIT.EDU> <2049@mit-eddie.MIT.EDU> Reply-To: willc@tekchips.UUCP (Will Clinger) Distribution: net Organization: Tektronix, Inc., Beaverton, OR. Lines: 56 Keywords: Scheme Summary: Reserved words are allowed In article <2049@mit-eddie.MIT.EDU> jbs@mit-eddie.UUCP (Jeff Siegal) writes: >Actually, redefining lambda or define would not change the meaning of >expressions like (define a b) or (lambda (x) (* x 2)). These are are >"special forms" and (if I remember my 6.001 correctly) the evaulator >does not look for their definitions in the current context before >actually doing the work involved (binding or procedure creation). So >actually the list of indentifiers which can not be redefined is the >list of special forms. > >Note however, that you can do the following: > >--> (DEFINE LAMBDA 1) >LAMBDA > >--> LAMBDA >1 > >--> ((LAMBDA (X) (+ X 1)) 1) >2 > >LAMBDA has been defined as a symbol bound to 1, but this does not >affect the normal usage of LAMBDA, which still works as expected(?). > >Jeff Siegal Whether you can do this or not is implementation-dependent. The Revised Revised Report on Scheme (MIT AI Memo 848) says "Some implementations [reserve] the identifiers that serve as keywords of special forms, while other implementations allow the keyword meaning of an identifier to be shadowed by lexical bindings." The code that Jeff wrote illustrates yet a third implementation, in which the shadowing is context-dependent. To write portable Scheme code, you have to assume that the keywords of special forms are reserved. That's one reason people are so fanatic about having the number of special forms be as small as possible. I don't know how Common Lisp stands on this issue. To judge by the program-analyzing algorithm on page 57 of Steele's "Common Lisp: the Language", the names of special forms are reserved when they appear in the car of a form, but I don't know what happens when they appear in other contexts. Common Lisp distinguishes between special forms and macros, however, and it is clear that macro names can be shadowed because they live in the "function" environment, which is lexical except for some special treatment of the global function environment. On the other hand, implementations of Common Lisp are explicitly allowed to implement certain macros as special forms, and I don't know how their names can be simultaneously reserved (because they are special forms) and shadowable (because they are macros). I'd appreciate any pointers to authoritative explanations of these two matters. Peace, William Clinger Tektronix Computer Research Laboratory willc%tekchips@tektronix