Path: utzoo!attcan!uunet!husc6!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: What's the value of lexical scoping? Message-ID: <22212@think.UUCP> Date: 19 Jun 88 02:11:18 GMT References: <24508@ucbvax.BERKELEY.EDU> <515@dcl-csvax.comp.lancs.ac.uk> <199@esosun.UUCP> <525@dcl-csvax.comp.lancs.ac.uk> Sender: usenet@think.UUCP Reply-To: barmar@kulla.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 57 In article <525@dcl-csvax.comp.lancs.ac.uk> simon@comp.lancs.ac.uk (Simon Brooke) writes: >>SETF >So you actually like overwriting cons cells without knowing what else is >pointing to them !? Either you aren't serious, or you haven't looked at >what SETF does. We all *know* REPLACs are dangerous; we all use them with >care (I hope). But SETF allows us to overwrite a cons cell without even >getting hold of it to identify it first! That is *terrifying*! and you are >going to put that horror into the hands of the innocent? I don't understand this point at all. How does SETF allow you to overwrite something without requiring you to know what you're overwriting? Maybe the problem you are referring to is the difference in behavior of SETF depending upon whether it is operating on a structured object or not. If it is modifying a structured object, it modifies the object, so all references to that object see the change. On the other hand, if it is given a character or a number, it modifies only the referent it is given. Examples: Structured: (setq x (cons 1 2)) (setq y x) (eql x y) => T (setf (car x) 3) x => (3 . 2) y => (3 . 2) (eql x y) => T Non-structured: (setq x #\a) (setq y x) (eql x y) => T (setf (char-bit x :meta) t) x => #\meta-a y => #\a (eql x y) => NIL However, these same inconsistencies would exist if you were forced to use the pre-SETF equivalents: (setq x (rplaca x 3)) (setq x (set-char-bit x :meta t)) (excuse the anachronism). The inconsistency isn't in SETF, but in the fact that the language allows side-effects to some data types but not others. If side effects on conses were not permitted, e.g. (defun rplaca (cons new-car) (cons new-car (cdr cons))) the two SETFs would be consistent regarding side effects. Barry Margolin Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar