How to delete only first appearance of element into list (elisp) ?
The Common Lisp sequence-editing functions (remove and friends) take a :count keyword argument:
Count, if supplied, limits the number of elements removed or deleted; if more than count elements satisfy the test, then of these elements only the leftmost or rightmost, depending on from-end, are deleted or removed, as many as specified by count. If count is supplied and negative, the behavior is as if zero had been supplied instead. If count is
nil, all matching items are affected.
For example:
ELISP> (require 'cl)
cl
ELISP> (remove* 1 '(1 2 1 3 1 4) :count 1)
(2 1 3 1 4)
ELISP> (remove* 1 '(1 2 1 3 1 4) :count 2)
(2 3 1 4)
ELISP> (remove* 1 '(1 2 1 3 1 4) :count 2 :from-end t)
(1 2 3 4)
(Note that Emacs already had its own function called remove, so the cl package has to use the name remove*.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With