From: Scott Thomas Haug
Subject: problems with delete
Date: 
Message-ID: <r1a90r76leo.fsf@kato.cs.wustl.edu>
Hello,

I'm using AKCL v. 1.625 on a Sparc 5 (and v. 1.615 on my linux box at home),
and I'm having some problems with the delete function.  Everything that I've
read, including the help documents within AKCL, indicate that delete is a
destructive function.  However, although it does return a list with the
appropriate element removed, it doesn't actually alter the list I send it.
Here's an example of what I'm talking about.

>(setf ls '(1 2 3))
(1 2 3)

>(delete 1 ls)
(2 3)

>ls
(1 2 3)

Am I mistaken about delete's functionality?  Am I mistaken about what
"destructive" means?  Or am I dealing with a buggy interpreter?  Any help on
this would be wonderful.

Thanks,

Scott

-- 
 ____        _   _   _   _               | Scott T. Haug - ····@cs.wustl.edu
/  __)__ ___| |_| |_| |_| |___  _ _ ___  | http://www.cs.wustl.edu/~sth2/
\__  \ _| _ \  _.  _|  _  | _ \/ | \ _ \ | Washington University in St. Louis
(____/__|___/\__|\__|_| |_|__,_|___/__ | | "I want to know God's thoughts...
(______________________________________/ | the rest are details." - A. Einstein

From: Barry Margolin
Subject: Re: problems with delete
Date: 
Message-ID: <219H.67$rL1.1037826@cam-news-reader1.bbnplanet.com>
In article <···············@kato.cs.wustl.edu>,
Scott Thomas Haug  <····@kato.cs.wustl.edu> wrote:
>Am I mistaken about delete's functionality?  Am I mistaken about what
>"destructive" means?  Or am I dealing with a buggy interpreter?  Any help on
>this would be wonderful.

This is answered in the FAQ.  In fact, this is the question that prompted
creation of the FAQ.  It's posted to the newsgroup every month, and a
pointer to its location on the web is posted every week, so there's no
excuse not to read it.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.
From: Marco Antoniotti
Subject: Re: problems with delete
Date: 
Message-ID: <lwzpjipped.fsf@galvani.parades.rm.cnr.it>
Scott Thomas Haug <····@kato.cs.wustl.edu> writes:

> Hello,
> 
> I'm using AKCL v. 1.625 on a Sparc 5 (and v. 1.615 on my linux box at home),
> and I'm having some problems with the delete function.  Everything that I've
> read, including the help documents within AKCL, indicate that delete is a
> destructive function.  However, although it does return a list with the
> appropriate element removed, it doesn't actually alter the list I send it.
> Here's an example of what I'm talking about.
> 
> >(setf ls '(1 2 3))
> (1 2 3)
> 
> >(delete 1 ls)
> (2 3)
> 
> >ls
> (1 2 3)
> 
> Am I mistaken about delete's functionality?  Am I mistaken about what
> "destructive" means?  Or am I dealing with a buggy interpreter?  Any help on
> this would be wonderful.
> 

No, you are not.  DELETE on the first element *is* confusing, but it
has a rational explanation.

With DELETE you modify the list "contained" in 'ls'.  Unfortunately
there is nothing in the semantics of DELETE which which states that
"when DELETE-ing the first element (i.e. the 'car' of the list) the
cons cell must be reused by 'shifting' the the remaining elements."
(This description of mine is in itself buggy :) ).

Therefore, DELETE returns a modified list, but 'ls' still contains the
reference to whatever was there before.  Hence it appears that 'ls'
has not changed.  To achieve this effect you need to explicitely setf
the result.  That's the way it is.

	(setf ls (delete 1 ls))


-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - (0)6 - 68 80 79 23, fax. +39 - (0)6 - 68 80 79 26
http://www.parades.rm.cnr.it
From: Thomas A. Russ
Subject: Re: problems with delete
Date: 
Message-ID: <ymig1l953fz.fsf@sevak.isi.edu>
This is probably in the FAQ.  At least it should be:

Scott Thomas Haug <····@kato.cs.wustl.edu> writes:


> I'm using AKCL v. 1.625 on a Sparc 5 (and v. 1.615 on my linux box at home),
> and I'm having some problems with the delete function.  Everything that I've
> read, including the help documents within AKCL, indicate that delete is a
> destructive function.  However, although it does return a list with the
> appropriate element removed, it doesn't actually alter the list I send it.
> Here's an example of what I'm talking about.

In Lisp, destructive (sequence) functions are ALLOWED to mutate their
argument.  They are NOT required to.  Therefore, you should always call
them for the value that they produce, not for any side-effect.

The point of having potentially destructive functions like DELETE
vs. REMOVE is that the implementation of DELETE can be more efficient.
As far as using them in a program is concerned, you should code so that
you can freely substitute the non-destructive version of any destructive
function you call.

> >(setf ls '(1 2 3))
> (1 2 3)
> 
> >(delete 1 ls)
> (2 3)

You need to call this for its value.

(setf ls (delete 1 ls))

> 
> >ls
> (1 2 3)
> 
> Am I mistaken about delete's functionality?  Am I mistaken about what
> "destructive" means?  Or am I dealing with a buggy interpreter?  Any help on
> this would be wonderful.

As noted above, delete's functionality is defined in terms of what value
it RETURNS.  It is also expressly allowed, but not required to, modify
its input argument.  Destructive means that you can't rely on the
structure of the input remaining untouched.  But that doesn't mean it
has to change anything.  It is perfectly within spec for DELETE to be
implmented by calling REMOVE.  The destructive nature of the functions
is merely a way to allow certain implementation techniques that can
reduce consing.  I would also not that there is in principle no way to
modify a list of one element so that it becomes NIL.  That means that 

   (delete 1 (list 1))    can't possibly use mutation to do the deletion.


> 
> Thanks,
> 
> Scott
> 
> -- 
>  ____        _   _   _   _               | Scott T. Haug - ····@cs.wustl.edu
> /  __)__ ___| |_| |_| |_| |___  _ _ ___  | http://www.cs.wustl.edu/~sth2/
> \__  \ _| _ \  _.  _|  _  | _ \/ | \ _ \ | Washington University in St. Louis
> (____/__|___/\__|\__|_| |_|__,_|___/__ | | "I want to know God's thoughts...
> (______________________________________/ | the rest are details." - A. Einstein

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu