[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about let binding behavior
From: |
tomas |
Subject: |
Re: Question about let binding behavior |
Date: |
Tue, 8 Oct 2024 10:05:16 +0200 |
On Tue, Oct 08, 2024 at 07:49:25AM +0000, Louis-Guillaume Gagnon wrote:
> Hi Tomas,
>
> Le 10/8/24 à 8:41 AM, tomas@tuxteam.de a écrit :
> > The binding (i.e. the "thing" linking the symbol baz to the value
> > '(...) is local. But what you do with that (setcdr... ) is to change
> > the value itself. Your function returns this (possibly changed) value.
> 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.
Oh. It is a constant (well, technically speaking "a literal" -- constant
has other meanings around here). This is another rabbit hole :-)
But -- either someone else chimes in, or it'll have to wait till the
afternoon, since I'm at $DAYJOB at the moment.
The short answer is that it's usually a good idea to use "fresh" storage
when you plan to mutate the (innards of the) "thing".
Some Lisps enforce literal immutability. Some others do funny things.
I.e. some moral equivalent of
(let ((foo (cons (cons one 1) (cons two 2)))) ...)
(of course you may use some deep-copy function or similar).
The fun part is that you get to choose at which depth you plan in
immutability :-)
Cheers
--
t
signature.asc
Description: PGP signature
- 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, Louis-Guillaume Gagnon, 2024/10/08
- Re: Question about let binding behavior,
tomas <=
- 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, 2024/10/08
- Re: Question about let binding behavior, Michael Heerdegen, 2024/10/08
- Re: Question about let binding behavior, Michael Heerdegen, 2024/10/08