This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

DELETE: An unexpected behavior

3 posts · 3022 views

Hello,

I've found a strange behavior in Clozure Common Lisp (but it's the same in Lispworks): if I apply "delete" function on a variable, the function returns the correct value, but, wherever the deleting item is the list first element, in the new variable value the item is deleted but not on the first index. Why?
? (setf a '(1 2 3 2 1 2))
(1 2 3 2 1 2)
? a
(1 2 3 2 1 2)
? (delete 1 a)
(2 3 2 2)
? a
(1 2 3 2 2)
? (delete 2 a)
(1 3)
? a
(1 3)
? 

Re: DELETE: An unexpected behavior

If you want the variable a to contain the list with all 1s deleted you need to write:
(setf a (delete 1 a))
CLHS DELETE says "delete, delete-if, and delete-if-not ... may modify sequence", what means that it's only the return value of DELETE that counts, while the old contents of a is unreliable afterwards, it may be modified or not.

- edgar

Re: DELETE: An unexpected behavior

Thank you