As Assem noted, there are extra spaces in your code that prevent remove
from being mishandled.
Please note that both delete
and remove
work for such purposes, if the list items can be correctly compared using equal
, which is used for both of them. If you want to compare using eq
instead, use the delq
or remq
.
The main differences between delete
and remove
(or delq
and remq
respectively) are that delete
deletes this element by side effect, i.e. modifies the given list in place, and remove
does not return, but returns a copy of this list with the deleted item.
(setq list1 '("foo" "bar" "baz")) (setq list2 (remove "bar" list1)) (message "list1: %s" list1) (message "list2: %s" list2) (setq list3 (delete "bar" list1)) (message "list1: %s" list1) (message "list3: %s" list3)
If you evaluate the code above, in the *Message*
buffer you will find the following output:
list1: (foo bar baz) list2: (foo baz) list1: (foo baz) list3: (foo baz)
As you can see, after calling remove
on list1
it has not changed. But after you wrote delete
on it, it has changed.
source share