all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Question about let binding behavior
@ 2024-10-08  6:21 Louis-Guillaume Gagnon
  2024-10-08  6:41 ` tomas
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Louis-Guillaume Gagnon @ 2024-10-08  6:21 UTC (permalink / raw)
  To: help-gnu-emacs

Dear all,

I'm a long time user but I've only recently started to dive into elisp 
programming. I'm a bit surprised by the following behavior.

Let's say I write the following silly function:

(defun foo (bar)
   (let ((baz '((quux . 0) (quuz . 0))))
     (if (> 10 bar)
     (setcdr (assoc 'quux baz) bar)
       (setcdr (assoc 'quuz baz) bar))
     baz))

Then the following evals:

(foo 1)
=> ((quux . 1) (quuz . 0))

(foo 100)
=> ((quux . 1) (quuz . 100))

I'm surprised that the list is not reset since I thought the binding was 
local to the function, but clearly I don't have the right mental model 
for elisp evaluation. For the actual application I ended up using 
copy-tree but I'd like to understand this better -- could someone 
explain or point out the relevant sections of the manual?

Cheers,
L-G

P.S. Please keep me in CC, I'm not subscribed to this list





^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Question about let binding behavior
@ 2024-10-09  8:34 Louis-Guillaume Gagnon via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 17+ messages in thread
From: Louis-Guillaume Gagnon via Users list for the GNU Emacs text editor @ 2024-10-09  8:34 UTC (permalink / raw)
  To: monnier; +Cc: help-gnu-emacs

> Does `C-h f quote RET` answer your question?
> (`quote` is the full-name of the ' you used in your code).

It does!

Merci,
L-G

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-10-18 11:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-08  6:21 Question about let binding behavior Louis-Guillaume Gagnon
2024-10-08  6:41 ` tomas
2024-10-08  7:49   ` Louis-Guillaume Gagnon
2024-10-08  8:05     ` tomas
2024-10-08 16:02       ` tomas
2024-10-09  8:01         ` Louis-Guillaume Gagnon via Users list for the GNU Emacs text editor
2024-10-09  8:13           ` Tomas Hlavaty
2024-10-09 23:39             ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-10-10  7:58               ` Tomas Hlavaty
2024-10-10 18:38                 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-10-18 11:25                   ` Rudolf Schlatte
2024-10-08  8:15     ` Joost Kremers
2024-10-08 22:27       ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-10-08 22:21     ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-10-08 15:47 ` [External] : " Drew Adams
2024-10-09  2:28 ` Stefan Monnier via Users list for the GNU Emacs text editor
  -- strict thread matches above, loose matches on Subject: below --
2024-10-09  8:34 Louis-Guillaume Gagnon via Users list for the GNU Emacs text editor

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.