all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: tomas@tuxteam.de
To: help-gnu-emacs@gnu.org
Subject: Re: Appending lists
Date: Wed, 16 Jun 2021 11:32:02 +0200	[thread overview]
Message-ID: <20210616093202.GC22979@tuxteam.de> (raw)
In-Reply-To: <YMnAscZtlQlRC8Yr@protected.localdomain>

[-- Attachment #1: Type: text/plain, Size: 1965 bytes --]

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

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2021-06-16  9:32 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14 16:36 Appending lists Pierpaolo Bernardi
2021-06-14 16:40 ` henri-biard
2021-06-14 18:21   ` Alexandr Vityazev
2021-06-15  0:46     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  8:27       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  9:18         ` tomas
2021-06-16  1:11           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16  7:28             ` tomas
2021-06-16  9:13               ` Jean Louis
2021-06-16  9:32                 ` tomas [this message]
2021-06-16 10:55                   ` Jean Louis
2021-06-16 16:44                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 18:00                       ` Using Emacs for business Jean Louis
2021-06-16 22:59                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:39                           ` Jean Louis
2021-06-17  0:16                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  7:09                               ` Jean Louis
2021-07-06  3:22                                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-06 20:23                                   ` Jean Louis
2021-07-06 20:41                                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-07  0:18                                       ` Jean Louis
2021-06-16  9:19               ` Appending lists Jean Louis
2021-06-16  9:35                 ` tomas
2021-06-16 10:57                   ` Jean Louis
2021-06-16 16:55                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 11:16                 ` Yuri Khan
2021-06-16 11:30                   ` Jean Louis
2021-06-16 11:54                     ` tomas
2021-06-16 17:31                       ` Jean Louis
2021-06-16 23:13                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:41                           ` Jean Louis
2021-06-16 13:01                     ` Philip Kaludercic
2021-06-16 16:59                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 17:36                       ` Jean Louis
2021-06-16 18:54                         ` tomas
2021-06-16 21:24                           ` Philip Kaludercic
2021-06-16 23:25                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  7:16                               ` tomas
2021-06-17  7:14                             ` tomas
2021-06-16 23:24                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:19                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 11:49                   ` [OT] Underground (was: Appending lists) tomas
2021-06-19  0:10                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 16:54                 ` Appending lists Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 18:49                   ` tomas
2021-06-16 21:40                     ` Jean Louis
2021-06-16 22:35                       ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-16 23:02                         ` Jean Louis
2021-06-17  0:00                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:44                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  7:20                           ` tomas
2021-06-16 23:39                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:31                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 14:22               ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-16 15:11                 ` tomas
2021-06-16 15:31                   ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-16 15:48                     ` tomas
2021-06-16 23:04                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  2:41                       ` [OFFTOPIC] " Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-17  6:09                         ` Arthur Miller
2021-06-17  6:29                           ` Stefan Monnier
2021-06-17 23:53                             ` Arthur Miller
2021-06-18 14:15                               ` Stefan Monnier
2021-06-19  0:04                                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-19  1:20                                   ` Eduardo Ochs
2021-06-19  2:18                                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-19  2:43                                   ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-21 15:07                                 ` Arthur Miller
2021-06-17  7:51                         ` tomas
2021-06-17  7:50                       ` tomas
2021-06-18 23:47                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-19  2:35                           ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-19  6:52                             ` tomas
2021-06-16 23:03                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 16:42               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 16:55                 ` [External] : " Drew Adams
2021-06-16 17:06                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 17:54                     ` Drew Adams
2021-06-16 23:49                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  7:54                         ` tomas
2021-06-17 12:41                           ` [OFFTOPIC] " Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-17 14:19                             ` tomas
2021-06-18 23:55                           ` [External] : " Emanuel Berg via Users list for the GNU Emacs text editor
  -- strict thread matches above, loose matches on Subject: below --
2021-06-17  3:18 Drew Adams
2021-06-17  7:48 ` tomas
2021-06-18 23:38   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-18 23:50   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-19  6:57     ` tomas
2021-06-19 21:31       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-14 16:44 Pierpaolo Bernardi
2021-06-15  0:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  1:47   ` henri-biard
2021-06-15  7:09     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-14 16:24 Pierpaolo Bernardi
2021-06-14 16:32 ` henri-biard
2021-06-14 16:08 henri-biard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210616093202.GC22979@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.