unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Robert Thorpe <rt@robertthorpeconsulting.com>
To: Tom <adatgyujto@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: hash strangeness
Date: Tue, 04 Nov 2014 01:57:48 +0000	[thread overview]
Message-ID: <87389zralf.fsf@robertthorpeconsulting.com> (raw)
In-Reply-To: <loom.20141103T221539-429@post.gmane.org> (message from Tom on Mon, 3 Nov 2014 21:29:17 +0000 (UTC))

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	other threads:[~2014-11-04  1:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-02 11:20 hash strangeness Tom
2014-11-02 12:09 ` Tom
2014-11-02 18:20   ` Thien-Thi Nguyen
2014-11-02 20:45     ` Tom
     [not found]     ` <mailman.12618.1414961152.1147.help-gnu-emacs@gnu.org>
2014-11-02 22:25       ` Pascal J. Bourguignon
2014-11-02 22:48       ` Barry Margolin
2014-11-03 21:29         ` Tom
2014-11-04  1:57           ` Robert Thorpe [this message]
2014-11-04  2:16           ` Michael Heerdegen
     [not found]       ` <<barmar-14233C.17480902112014@88-209-239-213.giganet.hu>
2014-11-04  3:04         ` Drew Adams
2014-11-04  7:39           ` Marcin Borkowski
     [not found] <mailman.12577.1414927271.1147.help-gnu-emacs@gnu.org>
2014-11-02 18:43 ` Pascal J. Bourguignon
2014-11-02 20:48   ` Tom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87389zralf.fsf@robertthorpeconsulting.com \
    --to=rt@robertthorpeconsulting.com \
    --cc=adatgyujto@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).