bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#9469: buffer-local variables seem to remember previous values


From: Drew Adams
Subject: bug#9469: buffer-local variables seem to remember previous values
Date: Sun, 11 Sep 2011 10:56:29 -0700

> > No, they should not be identical.

BTW, I should have said "It is not the case that they should be identical."  Not
quite the same thing.  There is no "should" here.  AFAIK, most Lisps do not
prescribe the behavior in this regard - it is up to the implementation.  But I'm
no expert on just what various Lisps define wrt this.

> > This is a classic Lisp gotcha.
> Thanks for the pointer, Drew.
> 
> I was unable to google up any information regarding this as being a
> classic gotcha.  Do you have any references?

No, I would have to google also.  I said it's "classic", which probably really
means that I was bitten by the same gotcha many, many moon ago, and I learned my
lesson then, in discussion with people who knew Lisp well.

Well, a quick google of "lisp quote list" brings me to this:
http://stackoverflow.com/questions/134887/when-to-use-quote-in-lisp

Search that page for "DO NOT USE QUOTE TO CREATE LISTS THAT YOU WILL LATER
MODIFY".  It says, "The spec allows the compiler to treat quoted lists as
constants."  I guess it  might be referring to the Common Lisp spec; dunno.

Scroll down further to the explanation by Matthias Benkard.  He points out that
when you use (quote (a b c)) the list (a b c) is created (the first time) by the
Lisp loader or reader, not by `quote'.  `quote' just returns that already
existing list.  `quote' does not create new list structure (or new symbols or
new strings or...).

You can probably find other, similar explanations by googling.

The real lesson, I think, is what I said earlier, which works for all Lisps: Do
not expect `quote' to create new list structure.

> If this is in fact "by design", then the manual should definitely say
> so in the quoting section.  Do I have to follow a different procedure
> to file a documentation bug?

I don't think the Elisp manual should say anything about it, but I'll let others
decide that.

The takeaway is, I think, that you should not depend on '(...) to create new
list structure each time it is evaluated.  I suppose the manual could say that.
Or it could perhaps clarify that `quote' does not create new Lisp objects; it
just returns the object that is its argument, unevaluated.  What can confuse
people is that the object already exists; it is provided by the reader (or the
loader).

I guess you could say that the reader treats list notation it encounters
similarly to what it does for symbol notation: if a symbol with the encountered
name already exists then it uses ("returns") that symbol.  Otherwise, it first
creates a symbol with that name.  IOW, the reader `intern's names it encounters.
Similarly, it handles list notation it encounters by either creating a new list
or returning an existing one.

Again, I'm no expert on this.  Perhaps someone else can explain it better.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]