all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Marcin Borkowski <mbork@wmi.amu.edu.pl>, help-gnu-emacs@gnu.org
Subject: RE: Why doesn't nconc change my variable?
Date: Sat, 4 Oct 2014 18:58:47 -0700 (PDT)	[thread overview]
Message-ID: <3867d7c2-936d-4441-91d6-3b12dc959391@default> (raw)
In-Reply-To: <87y4svl2ku.fsf@wmi.amu.edu.pl>

> (setq my-list ())
> (nconc my-list '("wtf"))
> 
> and my-list is still nil.  If, OTOH, I do
> (setq my-list ())
> (setq my-list (nconc my-list '("wtf")))
> 
> my-list is ("wtf").
> 
> Why is that so?  I though nconc is supposed to change all its
> arguments but the last one.  Is the latter construct a correct
> way of adding an element at the end of the list?

No, it's not supposed to do that. You discovered just what it
does do.  And you could have discovered it earlier by reading
some doc.  See the Elisp manual, node `Rearrangement' (found by
doing `i nconc' in the manual).

See also node `Sets and Lists', in particular this (about `delq',
but the same idea applies to other destructive list operations):

 Note that `(delq 'c sample-list)' modifies `sample-list' to splice
 out the third element, but `(delq 'a sample-list)' does not splice
 anything--it just returns a shorter list.  Don't assume that a variable
 which formerly held the argument LIST now has fewer elements, or that
 it still holds the original list!  Instead, save the result of `delq'
 and use that.  Most often we store the result back into the variable
 that held the original list:

     (setq flowers (delq 'rose flowers))



  reply	other threads:[~2014-10-05  1:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-05  1:36 Why doesn't nconc change my variable? Marcin Borkowski
2014-10-05  1:58 ` Drew Adams [this message]
2014-10-05  9:54   ` Marcin Borkowski
2014-10-05 10:52     ` Thorsten Jolitz
2014-10-05 16:29     ` Drew Adams
2014-10-05 16:38       ` Drew Adams
     [not found]   ` <mailman.10475.1412502895.1147.help-gnu-emacs@gnu.org>
2014-10-05 18:12     ` Pascal J. Bourguignon
2014-10-05 18:14     ` Pascal J. Bourguignon
2014-10-05 18:31     ` Pascal J. Bourguignon
     [not found] <mailman.10460.1412473030.1147.help-gnu-emacs@gnu.org>
2014-10-05  1:59 ` Pascal J. Bourguignon
2014-10-05  9:35   ` Marcin Borkowski
     [not found]   ` <mailman.10474.1412501757.1147.help-gnu-emacs@gnu.org>
2014-10-05 17:50     ` Pascal J. Bourguignon
2014-10-05 18:04 ` Pascal J. Bourguignon

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=3867d7c2-936d-4441-91d6-3b12dc959391@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@wmi.amu.edu.pl \
    /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.