On Mon, 28 Oct 2002, Josh Huber wrote:
Given this defun:
(defun jmh-test-func ()
(let (tv)
(setq tv '((?a) (?b)))
(push "testme" (cdr (assoc ?a tv)))
tv))
Why does the value returned keep accumulating data from previous
calls?
[...]
It's driving me crazy! I was under the impression let created a
local
binding which was destroyed when the let statement went out of scope?
Sure, the value of 'tv' is restored, but the constant list you are
setting it to isn't protected by the let at all...
[...]
Clearly, I must be missing something... :)
I would suggest that Emacs is reusing the same constant list each time
this is called, so that your `push' modifies that.
When I re-eval the defun, xemacs "forgets" the old values,
and the
insanity starts all over!
This would be consistent, since evaluating the definition again would
create a new constant list, replacing the previous one.
`let' protects the value you specify in it, not the values that are
referenced by protected values. So, in this case, `tv' will be restored
to the value it had outside the function but the content isn't.
Daniel
--
Impropaganda: Using propaganda techniques not in accordance with good sense,
good faith, or good morals... methods not consistent with the American pattern
of behavior based on Judeo-Christian ethics.
-- Edward L. Bernays, author of Crystallizing Public Opinion (1923)