[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 2016-05-23 Emacs News
From: |
John Mastro |
Subject: |
Re: 2016-05-23 Emacs News |
Date: |
Fri, 10 Jun 2016 09:45:42 -0700 |
Rolf Ade <address@hidden> wrote:
> So, ... '(1 3 2) defines some (defun local) "constant" ...?
>
> I'm still afraid, I miss completely some basic concept or syntax
> understanding.
That's right, though the fact that it's "defun local" is an
implementation detail. It could hypothetically be module/package local,
or global, etc. with a different implementation and compilation
strategy. (Also, I think "literal" is a better word for this than
"constant".)
The reason it's defun local in Emacs lisp is that each function object
(whether byte-compiled or not) contains the literals from that
function's definition.
It might (or might not) be more clear if you try this, which is
essentially the same as Marcin's recipe but we byte-compile the
function. You'll see that the list is stored in an vector of the
literals in the definition (in this case, the quoted list, symbols, and
strings). The reason I think this might help is that it makes it more
clear that the function itself is an object containing data.
(defun destructive-havoc ()
(let ((foo '(1 3 2)))
(message "before sort: %s" foo)
(sort foo #'<)
(message "after sort: %s" foo)))
(byte-compile 'destructive-havoc)
(pp-eval-expression '(symbol-function 'destructive-havoc))
(destructive-havoc)
(pp-eval-expression '(symbol-function 'destructive-havoc))
So, when you call `destructive-havoc', the call to `sort' is acting on
the list in that vector. That vector and its contents are part of the
function object for `destructive-havoc', so mutations to them are
permanent (relative to the function object itself).
Hope that helps,
John