From: Gary Hooyman
Subject: (delete (item sequence)) question
Date: 
Message-ID: <Qe_ZtJG00iQQE731Zj@andrew.cmu.edu>
Hi,

I am using Lucid 4.0 and have found a problem with the delete function. 
It seems that whenever I try to delete the first item from a sequence
the sequence is not modified as specified.  In other words

(setf   a-list   '(1 2 3 4))
> (1 2 3 4)
(delete   1    a-list)
>(2 3 4)
a-list
>(1 2 3 4)


What I plan to do is replace every instance of (delete item sequence)
with (setf sequence (remove item sequence)).  Has this been addressed in
more recent releases of Lucid CL?

From: R. Bharat Rao
Subject: Re: (delete (item sequence)) question
Date: 
Message-ID: <1992Jun1.181659.8358@m.cs.uiuc.edu>
·····@andrew.cmu.edu (Gary Hooyman) writes:
>Hi,

>I am using Lucid 4.0 and have found a problem with the delete function. 
>It seems that whenever I try to delete the first item from a sequence
>the sequence is not modified as specified.  In other words

>(setf   a-list   '(1 2 3 4))
>> (1 2 3 4)
>(delete   1    a-list)
>>(2 3 4)
>a-list
>>(1 2 3 4)

It is incorrect to rely on the side effects of a delete operation.  CL
simply specifies that executing a delete operation permits the system
to destructively modify the list in order to create the answer; but
does not specify what the modification (if any) to the original list
will be.

>What I plan to do is replace every instance of (delete item sequence)
>with (setf sequence (remove item sequence)).  Has this been addressed in
>more recent releases of Lucid CL?

It would (potentially) be more efficient to use delete instead of
remove above, as you appear to be discarding the sequence right away
(but dangerous if the orginal sequence is used elsewhere (say as a
sub-list in another list, in which case remove is coprrect).

Bharat
--
R. Bharat Rao                          E-mail: ······@cs.uiuc.edu 
AI Group, Beckman Institute for Advanced Science and Technology
405 N. Matthews, Urbana, IL 61801  (217)-244-1263 (O) 337-6498(H)
Electrical & Computer Engineering, University of Illinois, Urbana
From: David F. Skoll
Subject: Re: (delete (item sequence)) question
Date: 
Message-ID: <dfs.707430455@ro>
In <··················@andrew.cmu.edu> ·····@andrew.cmu.edu (Gary
Hooyman) writes:


>Hi,

>I am using Lucid 4.0 and have found a problem with the delete function. 

No, you haven't. :-)

Destructive functions in Lisp are not what you think they are.  A
destructive function is guaranteed to RETURN the value you want, but
can do anything with the original list passed to it.  The only correct
way to destructively delete an item from a list is to use:

	(setf the-list (delete item the-list))

The resulting value of the-list after:

	(delete item the-list)

is not specified.

--
David F. Skoll
From: Mark Kantrowitz
Subject: Common Questions [was Re: (delete (item sequence)) question]
Date: 
Message-ID: <1992Jun01.231041.216391@cs.cmu.edu>
Before replying to common pitfalls such as this, please check whether
the question is already answered by the Lisp FAQ. If so, mail the
poster a copy of the FAQ instead of posting to the newsgroup. This
way, we eliminate the half dozen postings that follow such a question,
and ensure that the answer is correct and complete.

If you feel that there is a problem with an answer included in the
Lisp FAQ, or feel that a question should be included in the FAQ,
please send mail to ········@think.com.

--mark