Re: Having trouble deleting first item in list
- From: Kent M Pitman <pitman@xxxxxxxxxxx>
- Date: Wed, 29 Jun 2005 02:57:24 GMT
"Paul F. Dietz" <dietz@xxxxxxx> writes:
> Kent M Pitman wrote:
>
> > You _must_ use the return value from DELETE and
> > not rely on DELETE for side-effect, since in the case that the element to
> > be deleted is the first element, DELETE will just _return_ the next tail of
> > the list that doesn't contain the to-be-deleted elements and will not
> > have a side-effect--there is no side-effect it could possibly have.
>
> Well, not necessarily. DELETE might have been implemented like this:
>
> (defun delete (item list)
> (cond
> ((null list) nil)
> ((eql (car list) item)
> (cond
> ((null (cdr list)) nil)
> (t
> (setf (car list) (cadr list))
> (setf (cdr list) (cddr list))
> (delete item list)))
> (t (setf (cdr list) (delete item (cdr list)))
> list)))
Yes, I've long known this. But
(a) this is makes predictable structure sharing unpredictable
(b) doesn't fix this bug:
> The bug is unavoidable if there is nothing in the list except
> the item to be deleted.
Given this, the above is an exercise in futility.
You still need the SETQ.
.
- References:
- Having trouble deleting first item in list
- From: jonathon
- Re: Having trouble deleting first item in list
- From: Kent M Pitman
- Re: Having trouble deleting first item in list
- From: Paul F. Dietz
- Having trouble deleting first item in list
- Prev by Date: Re: de threadibus
- Next by Date: Re: de threadibus
- Previous by thread: Re: Having trouble deleting first item in list
- Next by thread: Re: Having trouble deleting first item in list
- Index(es):
Relevant Pages
|
|