CLHS for
Function ... REMOVE-IF-NOT
... says:
remove-if-not test sequence &key from-end start end count key => result-sequence
...
...
remove-if-not return[s] a sequence from which the elements that satisfy the test have been removed.
And further it says (paraphrasing):
satisfy the test: for an element el
of seq
in the call (remove-if-not test seq :key key)
, whenever (test (key el))
returns true.
Furthermore,
[10]> (remove-if-not #'(lambda(x)(= 2 x)) '( (1) (2 2) (3 3 3)) :key #'length)
((2 2))
[11]> (remove-if-not #'(lambda(x)(/= 2 x)) '( (1) (2 2) (3 3 3)) :key #'length)
((1) (3 3 3))
[12]> (defvar qq '( (1) (2 2) (3 3 3)))
QQ
[13]> (remove-if-not #'(lambda(x)(/= 2 x)) qq :key #'length)
((1) (3 3 3))
[14]> qq
((1) (2 2) (3 3 3))
[15]> (eq qq (remove-if-not #'(lambda(x)(/= 2 x)) qq :key #'length))
NIL
[16]> (eq qq (remove-if-not #'(lambda(x)(/= 22 x)) qq :key #'length))
T
[17]>
So we don't really need to see the actual source code to find out what it does.
So the test
lambda function gets called for each element in the sequence, for instance
(funcall #'(lambda(x)(/= 2 x)) (length '(1)))
=
((lambda (x) (/= 2 x)) (length '(1)))
=
(let ((x (length '(1))))
(/= 2 x))
=
T
That's how function calls are made -- the lambda function's parameter gets the value of the argument in the function call, and then the lambda function's body gets evaluated under this binding.