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

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

Re: hash strangeness


From: Robert Thorpe
Subject: Re: hash strangeness
Date: Tue, 04 Nov 2014 01:57:48 +0000

Tom <adatgyujto@gmail.com> writes:

> Barry Margolin <barmar <at> alum.mit.edu> writes:
>> > 
>> > I expect '(a b c) to create a new list with these symbols
>> > every time it runs.
>> 
>> Why do you expect that?
>> 
>> '(a b c) is short for (quote (a b c)). quote returns its argument, it 
>> doesn't make a copy of it.
>
> Okay, but when I write '(a b c) in a function then I'd consider it
> an ad hoc list in the current context in the function, not as an object
> which outlives the exiting of the function and then returns in the
> next invocation, unexpectedly connecting the different invocations.

Think about C.  Suppose I have:
printf("Hello World!\n");
char *bar = "Goodbye";

In C89 and later both of the strings are constants, they're immutable
data.  If you try to write to one of the characters in "bar" then the
program will crash.  (In earlier versions of C the string would change,
often globally, connecting different invocations of the function.)

Emacs Lisp is similar here.  The list '(a b c) is made by the
interpreter when it's putting the expression into memory.  Quote means
"quote this thing written by the programmer when the program was
written".

>> I'm sure somewhere in the Elisp programming manual it mentions that you 
>> shouldn't use destructive functions on literal lists, like the Common 
>> Lisp spec does.
>
> Well, the quoting page doesn't mention it:
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Quoting.html

Yes.  It should probably say "This provides a way to include constant symbols
and constant lists".

I didn't understand this until recently either.

BR,
Robert Thorpe



reply via email to

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