On the page of the SEARCH function in the Specifications, one can read the example:
(search '(0 1) '(2 4 6 1 3 5) :key #'oddp) => 2
Can you explain how the comparison could work?
Indeed, the ODDP function returns a “generalized boolean”, which is
“an object used as a truth value, where the symbol nil represents
false and all other objects represent true.”
I’ve tried several things to check my understanding (under SBCL):
CL-USER> (coerce (oddp 6) 'integer)
; Debugger entered on #<SIMPLE-TYPE-ERROR expected-type: INTEGER datum: NIL>
CL-USER> (eql 0 nil)
NIL
CL-USER> (equal 0 nil)
NIL
CL-USER> (equalp 0 nil)
NIL
CL-USER> (type-of (oddp 6))
NULL
CL-USER> (eql 0 (oddp 6))
NIL
CL-USER> (equal 0 (oddp 6))
NIL
CL-USER> (equalp 0 (oddp 6))
NIL
So that means, that default :test
function of SEARCH is in theory not able to compare nil to 0.
Am I to understand this behavior of the SEARCH function is in fact specified by the example itself? Or is there something behind that implicitly compare a NULL object (or a nil value) to 0 and a true (t) value as 1? How does it work?