[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: binding question
From: |
Michael Heerdegen |
Subject: |
Re: binding question |
Date: |
Sun, 06 Oct 2013 14:39:09 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Hi Eric,
in LISP, lists (cons cells) are passed by reference. Thus, different
bindings can refer to the same list object, like here the variables a
and b:
(setq a '(1 2))
(setq b a) ; copies the reference to the list, not the list itself
(setcar a 'foo)
b
==> (foo 2)
> (defun main-entry-function ()
> ;; obviously this doesn't work as defvars are always special
> (let ((list-template list-template))
This creates a new local binding, but it references the same list object
in memory. If you change the structure of the referenced object, the
change is "visible" for all variables which are bound to this object.
You can create a real copy of the object with `copy-tree'. Or don't
destructively alter the list, but process the value with
non-destructive functions instead.
I'm sure there is a good explanation somewhere in the manual.
Regards,
Michael.