From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Why doesn't nconc change my variable? Date: Sat, 4 Oct 2014 18:58:47 -0700 (PDT) Message-ID: <3867d7c2-936d-4441-91d6-3b12dc959391@default> References: <87y4svl2ku.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1412474370 3168 80.91.229.3 (5 Oct 2014 01:59:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 5 Oct 2014 01:59:30 +0000 (UTC) To: Marcin Borkowski , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 05 03:59:23 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xab6Z-0000h1-7v for geh-help-gnu-emacs@m.gmane.org; Sun, 05 Oct 2014 03:59:23 +0200 Original-Received: from localhost ([::1]:45849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xab6Y-0007JA-Vg for geh-help-gnu-emacs@m.gmane.org; Sat, 04 Oct 2014 21:59:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xab6H-0007J5-NH for help-gnu-emacs@gnu.org; Sat, 04 Oct 2014 21:59:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xab66-0004ie-Sv for help-gnu-emacs@gnu.org; Sat, 04 Oct 2014 21:59:05 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:20155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xab66-0004ia-Mf for help-gnu-emacs@gnu.org; Sat, 04 Oct 2014 21:58:54 -0400 Original-Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s951wpe0029557 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 5 Oct 2014 01:58:52 GMT Original-Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s951wngk012828 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 5 Oct 2014 01:58:51 GMT Original-Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s951wnJn010524; Sun, 5 Oct 2014 01:58:49 GMT In-Reply-To: <87y4svl2ku.fsf@wmi.amu.edu.pl> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8.2 (807160) [OL 12.0.6691.5000 (x86)] X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100277 Archived-At: > (setq my-list ()) > (nconc my-list '("wtf")) >=20 > and my-list is still nil. If, OTOH, I do > (setq my-list ()) > (setq my-list (nconc my-list '("wtf"))) >=20 > my-list is ("wtf"). >=20 > 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))