[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Order of arguments to sequence :TEST functions



CLtL page 247 says
	... (funcall testfn item (keyfn x)) ...
I'm curious to know why this order was chosen instead of
	... (funcall testfn (keyfn x) item) ...
When I hand code predicates, I usually put the more variable thing first
and the more constant thing second, as in
	(defun poor-mans-position (array frob)
	  (dotimes (index (length array))
	    (when (eql (aref array index) frob)
	      (return index))))

The (Symbolics implementation) of xCASE macros are similar, in that the
keyform is the more variable and the clauses are the more constant, and
it is roughly (eql keyform clause) or (member keyform clause) as
appropriate.  Since EQL is commutative, this doesn't matter much.

The xTYPECASE macros are somewhat similar: they keyform is the more
variable and the type is more contant.  Of course, this is largely based
on the order of arguments to TYPEP.  Still, there is a potential
analogy.

Generally, I view "is it XYZ" to be (test it XYZ).  This generally holds
except for the sequence functions, such as FIND, where I view XYZ being
the item and "it" being the element of the sequence.

What I was trying to do was use FIND to find an item of a certain type,
as in
	(find type sequence :test #'typep)
but the order of the arguments as defined in CLtL is backwards.  The
closest I could get was
	(find type sequence :key #'type-of :test-not #'subtypep)
with the knowledge that there was no exact match (it was a flavor
mixin).  

Yes, I know I can use find-if, and that's what I'm really doing.  Was
there a reason for the ordering choice?  Does anybody depend on it, or
know of somebody that does?  Is there any chance of CLtL'89 reversing
it (and documenting the reason in the text)?