all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Mastro <john.b.mastro@gmail.com>
To: emacs-tangents@gnu.org
Cc: Rolf Ade <rolf@pointsman.de>, Marcin Borkowski <mbork@mbork.pl>
Subject: Re: 2016-05-23 Emacs News
Date: Fri, 10 Jun 2016 09:45:42 -0700	[thread overview]
Message-ID: <CAOj2CQTdFYoY-fWU+UuwqC5gxa7cSafV9nj5YkHoNWHH3ZHBdw@mail.gmail.com> (raw)
In-Reply-To: <87r3c5cbmf.fsf@linux-qg7d.fritz.box>

Rolf Ade <rolf@pointsman.de> 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



  reply	other threads:[~2016-06-10 16:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-23 16:44 2016-05-23 Emacs News Sacha Chua
2016-06-10  0:04 ` Rolf Ade
2016-06-10 10:30   ` Nicolas Richard
2016-06-10 13:37     ` Rolf Ade
2016-06-10 13:52       ` Marcin Borkowski
2016-06-10 15:22         ` Rolf Ade
2016-06-10 16:45           ` John Mastro [this message]
2016-06-10 14:55       ` Nicolas Richard
2016-06-10 16:01         ` Rolf Ade

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

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

  git send-email \
    --in-reply-to=CAOj2CQTdFYoY-fWU+UuwqC5gxa7cSafV9nj5YkHoNWHH3ZHBdw@mail.gmail.com \
    --to=john.b.mastro@gmail.com \
    --cc=emacs-tangents@gnu.org \
    --cc=mbork@mbork.pl \
    --cc=rolf@pointsman.de \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.