This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: remove! bug


* teong leong chuah [2010-05-28 16:15+0200] writes:

> Sorry I should have explained more in the previous post.
> The bug is that remove! is unable to remove the first element of the
> list that satisfy the predicate.
> the first element ('a 1) was not removed from list1 while the second
> element ('b 2) was removed successfully.
>
> Is that normal or is that a bug?

That's normal; and a lesson that every lisper needs to learn.  The idea
is that remove! should be used in the same way as remove.  In fact
remove would be a valid implementation for remove! because remove! may
or _may not_ have side-effects.  That means you can only count on the
value returned by remove! but not on the side-effect.  And the code
should look like:

(set! list2 (remove! (lambda (x) (equal? (car x) 'a)) list2))

This is the same for reverse!, append! and most of the traditional Lisp
functions that have both a destructive and a non-destructive variant.

Helmut


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]