[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `append' vs. `nconc'

From: tomas
Subject: Re: `append' vs. `nconc'
Date: Thu, 31 Dec 2015 10:30:45 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

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.

- -- tomás
Version: GnuPG v1.4.12 (GNU/Linux)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]