barmar@think.com (11/29/89)
In article <9893@zodiac.ADS.COM> rshu@ads.com (Richard Shu) writes: >I guess there's a corollary that says: make sure you create new copies of >lists if that's what you want. Don't use QUOTE (') to cons up data structures. >If you don't like LIST, use the BACKQUOTE macro (`). I've been shafted by >variations of your bug where the problem was using QUOTE instead of BACKQUOTE. You are assuming that backquote always creates new lists. The definition of backquote doesn't say what it produces. It may do as much sharing as it can. In particular, if a backquoted expression contains no comma, then the backquote is equivalent to a quote. An implementation would be justified in translating (defun foo (a) `(,a b c)) into (defun foo (a) (cons a '(b c))) Then (eq (foo) (foo)) => NIL, but (eq (cdr (foo)) (cdr (foo))) => T. And if you NCONC something to the end of (foo) you may change the value of future calls. Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar
folta@tove.umd.edu (Wayne Folta) (11/29/89)
In article <31793@news.Think.COM> barmar@think.com writes: >You are assuming that backquote always creates new lists. The definition >of backquote doesn't say what it produces. It may do as much sharing as it >can. In particular, if a backquoted expression contains no comma, then the >backquote is equivalent to a quote. Exactly! In fact, that is what happened to me when using Apple's ACL. I am new to LISP and so I lost several hours trying to figure out why certain data were mysteriously changing. (Of course, the problem was that they were 'eq'.) [As I remember it, I created a backquoted list of two sublists, one with comma and one without. The sublist without was reused, the part with was not. It sure helped disguise the problem--not that it would have been clear to this novice anyhow :-)] Wayne Folta (folta@cs.umd.edu 128.8.128.8)