From: ····@vladimir.ucsb.edu
Subject: Lisp delete
Date: 
Message-ID: <1208@ucsbcsl.ucsb.edu>
I have a question about my Lisp program:

I have the statement

       (delete x l2 :test #'equal)

where x is a known sublist of l2.
I step the program, and it shows the delete occuring as it should (it
supposedly destructively alters l2).  But 5 lines later, step shows
the value of l2 to be its original value.

What should I know about delete?
Any help would be appreciated.

Thanx.

Gene.

From: Simon Leinen
Subject: Re: Lisp delete
Date: 
Message-ID: <SIMON.91Aug24130919@liasun1.epfl.ch>
In article <····@ucsbcsl.ucsb.edu> ····@vladimir.ucsb.edu writes:

	  (delete x l2 :test #'equal)

   [...] But 5 lines later, step shows the value of l2 to be its
   original value.

Apparently you fell into the common trap of destructive operations
that sometimes ``fail to be destructive''; you have to use the result
of the DELETE function:

	(setq l2 (delete x l2 :test #'equal))

To cite Guy Steele's CLtL2, page 398, on sequence-modifying functions:

   ``Each of these functions alters the contents of a sequence or
     produces an altered copy of a given sequence.''
-- 
Simon.
From: R. Bharat Rao
Subject: Re: Lisp delete
Date: 
Message-ID: <bharat.683037662@milton>
In <····@ucsbcsl.ucsb.edu> ····@vladimir.ucsb.edu writes:

>I have the statement
>       (delete x l2 :test #'equal)

>where x is a known sublist of l2.
>I step the program, and it shows the delete occuring as it should (it
>supposedly destructively alters l2).  But 5 lines later, step shows
>the value of l2 to be its original value.

>What should I know about delete?

delete is destructive all right, but in Common Lisp destructive merely
means ``can destroy the arguments (here: l2) in order to create the
results''.  When (delete x l2 :test #'equal) is evaluated, it RETURNS
the result you want.  However, l2 is not setq'd to that value.

So what you need to do is ...

(setq l2 (delete x l2 :test #'equal))

This is a common mistake (Steele warns about it virtually any time a
destructive operation is defined).

>Gene.

-Bharat
--
R. Bharat Rao                         E-mail: ······@cs.uiuc.edu
Beckman Institute for Advanced Science and Technology
Electrical & Computer Engineering, University of Illinois, Urbana
Snail Mail: Beckman Institue, 405 N. Matthews, Urbana, IL 61801
From: Kostruba
Subject: Re: Lisp delete
Date: 
Message-ID: <1260@ucsbcsl.ucsb.edu>
If the "destructive version" of delete (and other functions) don't
change the argument in place, why is there a "destructive" version?

Why not just use remove?
From: Barry Margolin
Subject: Re: Lisp delete
Date: 
Message-ID: <1991Aug28.031257.22909@Think.COM>
In article <····@ucsbcsl.ucsb.edu> ····@vladimir.ucsb.edu (Kostruba) writes:
>If the "destructive version" of delete (and other functions) don't
>change the argument in place, why is there a "destructive" version?
>
>Why not just use remove?

The destructive version is *allowed* to modify its argument, but isn't
required to.  The non-destructive version is *prohibited* from modifying
its argument.

You use DELETE when you don't care if the list gets modified, for its
potential efficiency.  You use REMOVE when you expect to need the original
list.

I've never heard of a version of DELETE that doesn't modify the list.  The
discussion that we've been having is over the *way* that it does this.  The
spec only says that the original list structure can be reused and altered
to form the result, but doesn't define the precise type of reuse that must
be done.
-- 
Barry Margolin, Thinking Machines Corp.

······@think.com
{uunet,harvard}!think!barmar