Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!barmar From: barmar@mit-eddie.UUCP Newsgroups: comp.lang.lisp Subject: Re: Against the TIde of Common LISP Message-ID: <4934@mit-eddie.MIT.EDU> Date: Tue, 24-Feb-87 03:17:52 EST Article-I.D.: mit-eddi.4934 Posted: Tue Feb 24 03:17:52 1987 Date-Received: Thu, 26-Feb-87 23:48:20 EST References: <2624@well.UUCP> <2626@well.UUCP> Reply-To: barmar@eddie.MIT.EDU (Barry Margolin) Organization: MIT, EE/CS Computer Facilities, Cambridge, MA Lines: 43 In article <2626@well.UUCP> jjacobs@well.UUCP (Jeffrey Jacobs) writes: Describing a way for SET to assign to lexical variables: >(DEFUN FOO (X Y Z) (SET X (CONS Y Z))) > >The compiler would have to generate code that would effectively >be equal to > >(COND ((EQ X 'X) (SETQ X (CONS Y Z))) > ((EQ X 'Y) (SETQ Y (CONS Y Z))) > ((EQ X 'Z) (SETQ Z (CONS Y Z))) > (T (SET-SYMBOL-VALUE X (CONS Y Z))))) That is the wrong thing, though. Consider FOO being used in the following: (DEFUN FOO-CALLER (ARG1 ARG2) (LET ((X 3)) (FOO 'X ARG1 ARG2) (PRINT X))) The X that is passed to FOO is in the lexical scope of FOO-CALLER, so it is the one that one would expect to be assigned. One of the goals of lexical scoping is that it should not make any difference to the caller what the names of locals are in a function; if a lexical variable is renamed, the only places you have to look for references to the variable is within the lexical scope of that variable. The parameters to FOO are not lexical variables because they can be referenced outside the function. I will admit that there are uses for this type of thing; for example, in an object-oriented programming system implemented using lexical variables, one might have a SET-INSTANCE-VARIABLE function that takes the name of an instance variable. However, this would probably differ from FOO because it wouldn't have the T clause, since it is ONLY interested in lexical variables. I doubt that there is a use for the generality of the FOO example, in which SET will set either a lexical or special. -- Barry Margolin ARPA: barmar@MIT-Multics UUCP: ..!genrad!mit-eddie!barmar