Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Sort is destructive (was Re: how to use nreverse?)

From: Kelly Murray <k...@IntelliMarket.Com>
Subject: Sort is destructive (was Re: how to use nreverse?)
Date: 1999/02/10
Message-ID: <36C1EC87.13870436@IntelliMarket.Com>#1/1
X-Deja-AN: 442938662
Content-Transfer-Encoding: 7bit
References: <ud83jlij9.fsf@res.raytheon.com> <36C06282.EABBBE59@computer.org> <m2btj317g8.fsf@sophia.axel.nom> <36C10342.F8F7EF13@computer.org>
Content-Type: text/plain; charset=us-ascii
Organization: IntelliMarket.Com
Mime-Version: 1.0
Newsgroups: comp.lang.lisp

Christopher J. Vogt wrote:
> > i see now that '(1 1) was not being copied but it got pointed to by
> > acc.  i see i can avoid the problem by using (list 1 1) or (copy-list
> > '(1 1)).
> >
> > hmm that was subtle, but i am learning.
> 
> Indeed it is subtle, and just about every Lisp programmer has been bit
> by this when she was learning Lisp, and will never forget the lesson.
> 

I thought I'd add that even this experienced lisp programmer was
bitten by the destructive operation of #'sort
spending many hours tracking down the bug it caused.

The problem was that AllegroStore copies a list every 
time you access an objects slot, so doing a #'sort on the
list didn't have any effect on the persistent data.

But with my OODB, slot-access just returns a pointer to the list,
and thus sorting the list destructively modifies it in the DB.

The problem manifests itself by items disappearing from the list,
as referenced by the old head of the list, which is no longer
the head of the list after the sort.   
And of course, the bug doesn't show up if the list was sorted
already, so the pointers don't get reshuffled.  

I think #'sort should be renamed #'nsort ...

-Kelly Murray  k...@intellimarket.com  http://www.intellimarket.com