[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Appending lists
From: |
tomas |
Subject: |
Re: Appending lists |
Date: |
Wed, 16 Jun 2021 11:32:02 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Wed, Jun 16, 2021 at 12:13:21PM +0300, Jean Louis wrote:
> * tomas@tuxteam.de <tomas@tuxteam.de> [2021-06-16 10:29]:
> > On Wed, Jun 16, 2021 at 03:11:43AM +0200, Emanuel Berg via Users list for
> > the GNU Emacs text editor wrote:
> > > tomas wrote:
> > >
> > > > (setq thing (copy-sequence '(one two three four five six)))
> > > > (setq thang (cddr thing))
> > > >
> > > > thang => (three four five six)
> > > >
> > > > (nreverse thing) => (six five four three two one)
> > > >
> > > > thing => (one)
> > > >
> > > > thang => (three two one)
> > > > ; now this is what I was after. Who the heck "changed my
> > > > ; variable!?" Who is General Failure and why is he reading
> > > > ; my disk?
> > >
> > > Well, let's see, `nreverse' has updated the data without
> > > setting the variables to whatever desired values they should
> > > take
> >
> > It can't. It's a function.
> >
> > Doing (foo x y) will *never* change "the variable x" -- unless
> > foo is a macro/special form.
>
> (setq list-1 '(1 2 3))
> (setq list-2 '(A B))
> (nconc list-1 list-2) ⇒ (1 2 3 A B)
> list-1 ⇒ (1 2 3 A B)
> nconc is a built-in function in ‘C source code’.
>
> So it obviously changes the variable `list-1' from (1 2 3) to (1 2 3 A
> B) -- how do you explain that?
No. A thousand times no. The variable list-1 contained a ref to some
cons cell (behind the scenes it's just a (perhaps tagged) pointer).
**THIS VARIABLE HASN'T CHANGED** after you did that nconc. The variable
list-1 still contains a ref to exactly the same cons cell.
What happens is that you changed the list somewhere downstream.
> So far I know from Common Lisp those functions starting with "n" are
> common with side effects.
Judging by what you write, I have the impression that you haven't
quite understood Common Lisp (this part works exactly the same
there). But I might be wrong and this a huge misunderstanding.
Cheers
- t
signature.asc
Description: Digital signature
- Appending lists, (continued)
- Re: Appending lists, Pierpaolo Bernardi, 2021/06/14
- Appending lists, henri-biard, 2021/06/14
- Re: Appending lists, Alexandr Vityazev, 2021/06/14
- Re: Appending lists, Emanuel Berg, 2021/06/14
- Re: Appending lists, Emanuel Berg, 2021/06/15
- Re: Appending lists, tomas, 2021/06/15
- Re: Appending lists, Emanuel Berg, 2021/06/15
- Re: Appending lists, tomas, 2021/06/16
- Re: Appending lists, Jean Louis, 2021/06/16
- Re: Appending lists,
tomas <=
- Re: Appending lists, Jean Louis, 2021/06/16
- Re: Appending lists, Emanuel Berg, 2021/06/16
- Using Emacs for business, Jean Louis, 2021/06/16
- Re: Using Emacs for business, Emanuel Berg, 2021/06/16
- Re: Using Emacs for business, Jean Louis, 2021/06/16
- Re: Using Emacs for business, Emanuel Berg, 2021/06/16
- Re: Using Emacs for business, Jean Louis, 2021/06/17
- Re: Appending lists, Jean Louis, 2021/06/16
- Re: Appending lists, tomas, 2021/06/16
- Re: Appending lists, Jean Louis, 2021/06/16