[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Appending lists
From: |
Stefan Monnier |
Subject: |
Re: Appending lists |
Date: |
Wed, 16 Jun 2021 18:35:35 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> To put a point across it would be better to announce or make a title
> that you don't talk how "variable never changes", but you talk about
> the structures in memory and somewhat interesting though practically
> within the spoken context useless information. What matters for
> programmer is that variable A instead of holding value 1 now has value
> 2, that is a change, and how that change was internally accomplished
> does not change the fact that A is now not 1 but is 2. (づ。◕‿‿◕。)づ
That's the problem with mutation.
In a language like Haskell where mutation is not allowed, when you have
x = [1, 2, 3]
then the value held in variable `x` is really a list of 3 elements.
But in a language like ELisp, when you have
(let ((x (list 1 2 3))) ...
the value held in variable `x` is not a list of 3 elements: it's really
nothing more than a reference to a location in memory holding a cons
cell (constraints in ELisp's type system ensure that this location in
memory will always hold a cons cell). The values held in the `car/cdr`
of that cons cell will depend on the current memory state, they are not
part of "the value held in `x`".
The vast majority of ELisp code never uses `setcar/setcdr`, tho, so we
tend to overlook this inconvenient truth and talk (and think) about
those values as if we were in the presence of immutable data.
That's why `nconc`, `nreverse`, `sort`, and other similar side-effecting
functions need to be used with a lot of care.
Stefan
- Re: Appending lists, (continued)
- Re: Appending lists, tomas, 2021/06/17
- Re: Appending lists, Emanuel Berg, 2021/06/16
- Re: Appending lists, Emanuel Berg, 2021/06/16
- [OT] Underground (was: Appending lists), tomas, 2021/06/16
- Re: [OT] Underground (was: Appending lists), Emanuel Berg, 2021/06/18
- Re: Appending lists, Emanuel Berg, 2021/06/16
- Re: Appending lists, tomas, 2021/06/16
- Re: Appending lists, Jean Louis, 2021/06/16
- Re: Appending lists,
Stefan Monnier <=
- Re: Appending lists, Jean Louis, 2021/06/16
- Re: Appending lists, Emanuel Berg, 2021/06/16
- Re: Appending lists, Emanuel Berg, 2021/06/16
- Re: Appending lists, tomas, 2021/06/17
- Re: Appending lists, Emanuel Berg, 2021/06/16
- Re: Appending lists, Emanuel Berg, 2021/06/16
- Re: Appending lists, Stefan Monnier, 2021/06/16
- Re: Appending lists, tomas, 2021/06/16
- Re: Appending lists, Stefan Monnier, 2021/06/16
- Re: Appending lists, tomas, 2021/06/16