Ah yes, nice name. I put such a function into TXR Lisp, as well as a lazy
workalike called keep-if*.
(The : symbol in lambda lists denotes the start of optional parameters.
A rest param is introduced by a consing dot.)
Functions remove-if, keep-if, remove-if* and keep-if*
Syntax:
(remove-if <predicate-function> <list> : <key-function>)
(keep-if <predicate-function> <list> : <key-function>)
(remove-if* <predicate-function> <list> : <key-function>)
(keep-if* <predicate-function> <list> : <key-function>)
Description
The remove-if function produces a list whose contents are those
of <list> but with those elements removed which satisfy <predi-
cate-function>. Those elements which are not removed appear in
the same order. The result list may share substructure with the
input list, and may even be the same list object if no items are
removed.
The optional <key-function> specifies how each element from the
<list> is transformed to an argument to <predicate-function>. If
this argument is omitted or specified as nil, then the predicate
function is applied to the elements directly, a behavior which
is identical to <key-function> being (fun identity).
The keep-if function is exactly like remove-if, except the sense
of the predicate is inverted. The function keep-if retains those
items which remove-if will delete, and removes those that
remove-if will preserve.
The remove-if* and keep-if* are like remove-if and keep-if, but
produce lazy lists.
Examples:
;; remove any element numerically equal to 3.
(remove-if (op = 3) '(1 2 3 4 3.0 5)) -> (1 2 4 5)
;; remove those pairs whose first element begins with "abc"
[remove-if (op equal [@1 0..3] "abc")
'(("abcd" 4) ("defg" 5))
car]
-> (("defg 5))
;; equivalent, without key function
(remove-if (op equal [(car @1) 0..3] "abc")
'(("abcd" 4) ("defg" 5)))
-> (("defg 5))