[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about let binding behavior
From: |
Joost Kremers |
Subject: |
Re: Question about let binding behavior |
Date: |
Tue, 08 Oct 2024 10:15:11 +0200 |
On Tue, Oct 08 2024, Louis-Guillaume Gagnon wrote:
> That makes sense, but I guess I'm more surprised that the list itself is
> only evaluated a single time -- I would naively have expected for the
> list to be created anew every time the function is called but that's
> evidently not what's happening.
The reason for that is that the list is a constant: the literal list is
part of the code, and the object is created when the defun is evaluated.
The object will stick around, even if the binding to it (baz) is local to
the function.
Now, what I honestly don't know is if the object can at some point be
garbage-collected, but I suspect it can. I wouldn't bet on it staying
around, anyway.
If you don't want the object to stick around, make sure you create it in
the function:
```
(defun foo (bar)
(let ((baz (list (cons 'quux 0) (cons 'quuz 0))))
(if (> 10 bar)
(setcdr (assoc 'quux baz) bar)
(setcdr (assoc 'quuz baz) bar))
baz))
```
--
Joost Kremers
Life has its moments
- Re: Question about let binding behavior, (continued)
- Re: Question about let binding behavior, tomas, 2024/10/08
- Re: Question about let binding behavior, Louis-Guillaume Gagnon, 2024/10/08
- Re: Question about let binding behavior, tomas, 2024/10/08
- Re: Question about let binding behavior, tomas, 2024/10/08
- Re: Question about let binding behavior, Louis-Guillaume Gagnon, 2024/10/09
- Re: Question about let binding behavior, Tomas Hlavaty, 2024/10/09
- Re: Question about let binding behavior, Stefan Monnier, 2024/10/09
- Re: Question about let binding behavior, Tomas Hlavaty, 2024/10/10
- Re: Question about let binding behavior, Stefan Monnier, 2024/10/10
- Re: Question about let binding behavior, Rudolf Schlatte, 2024/10/18
- Re: Question about let binding behavior,
Joost Kremers <=
- Re: Question about let binding behavior, Michael Heerdegen, 2024/10/08
- Re: Question about let binding behavior, Michael Heerdegen, 2024/10/08
RE: [External] : Question about let binding behavior, Drew Adams, 2024/10/08
Re: Question about let binding behavior, Stefan Monnier, 2024/10/08
Re: Question about let binding behavior, Louis-Guillaume Gagnon, 2024/10/09