From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: `append' vs. `nconc' Date: Thu, 31 Dec 2015 10:30:45 +0100 Message-ID: <20151231093045.GB19900@tuxteam.de> References: <568164D8.6050700@ojkastl.de> <87io3iyr7t.fsf@debian.uxu> <87si2kezg1.fsf@mithlond.arda> <87a8osrlj4.fsf_-_@debian.uxu> <87lh8bgafa.fsf@mithlond.arda> <87r3i3ch63.fsf@kuiper.lan.informatimago.com> <87si2jqee2.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1451556349 11011 80.91.229.3 (31 Dec 2015 10:05:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 31 Dec 2015 10:05:49 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 31 11:05:45 2015 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 1aEa76-0003xF-4I for geh-help-gnu-emacs@m.gmane.org; Thu, 31 Dec 2015 11:05:44 +0100 Original-Received: from localhost ([::1]:55237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aEa75-0008NP-99 for geh-help-gnu-emacs@m.gmane.org; Thu, 31 Dec 2015 05:05:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aEa6u-0008NJ-RR for help-gnu-emacs@gnu.org; Thu, 31 Dec 2015 05:05:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aEa6r-00039W-LI for help-gnu-emacs@gnu.org; Thu, 31 Dec 2015 05:05:32 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]:59621 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aEa6r-00039S-Fr for help-gnu-emacs@gnu.org; Thu, 31 Dec 2015 05:05:29 -0500 Original-Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1aEZZF-0005P8-GJ for help-gnu-emacs@gnu.org; Thu, 31 Dec 2015 10:30:45 +0100 In-Reply-To: <87si2jqee2.fsf@debian.uxu> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 5.199.139.25 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:108550 Archived-At: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, Dec 31, 2015 at 08:13:41AM +0100, Emanuel Berg wrote: > "Pascal J. Bourguignon" > writes: > > > You must remember the literal/immutable status of > > each item at each level. > > > > Since you are incapable of remembering it, you > > should assume that the whole input data is immutable > > and write purely functional code (ie. use append, > > not nconc) in general. > > OK, so you use `nconc' when you yourself create the > lists by hand and thus know they are not empty, all > the while using `list' and not ', and when done you > assign the result to a variable associated with a list > INSTEAD of using `nconc' directly because that > variable can hold the empty list, i.e. nil, which > `nconc' contrary to `append' cannot handle. And you do > this to save time! Or, to squint differently at it: you use nconc when "nobody is looking", i.e. when you *know* that there are no references to the data being mutated (unless you *want* that the world changes for those other watchers too). OTOH, nconc is "just an optimization", because GC isn't ideal. So a good rule of thumb: - it's very obvious It's a local value you are keeping in your little scope. (One might argue that then, it's an idiomatic way to emphasize this fact to the (human) reader...) - you are really pressed for time It's somewhere deep in many nested loops. Otherwise... just don't use it. Regards - -- tomás -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlaE9cUACgkQBcgs9XrR2kZmSQCfRKgjktl8mIPS6/Eh/XkkHNiE 0E8AoIFZKrKi9bB1q0Ujul/IdXad8WX6 =Q8vS -----END PGP SIGNATURE-----