CLCS
Function

count, count-if, count-if-not

count item sequence &key from-end start end key test test-not ⇒ n

count-if predicate sequence &key from-end start end key ⇒ n

count-if-not predicate sequence &key from-end start end key ⇒ n

Arguments and Values

iteman object.
sequencea proper sequence.
predicatea designator for a function of one argument that returns a generalized boolean.
from-enda generalized boolean. The default is false.
testa designator for a function of two arguments that returns a generalized boolean.
test-nota designator for a function of two arguments that returns a generalized boolean.
start, endbounding index designators of sequence. The defaults for start and end are 0 and nil, respectively.
keya designator for a function of one argument, or nil.
na non-negative integer less than or equal to the length of sequence.

Description

count, count-if, and count-if-not count and return the number of elements in the sequence bounded by start and end that satisfy the test.

The from-end has no direct effect on the result. However, if from-end is true, the elements of sequence will be supplied as arguments to the test, test-not, and key in reverse order, which may change the side-effects, if any, of those functions.

Examples

 (count #\a "how many A's are there in here?") ⇒  2
 (count-if-not #'oddp '((1) (2) (3) (4)) :key #'car) ⇒  2
 (count-if #'upper-case-p "The Crying of Lot 49" :start 4) ⇒  2 

Exceptional Situations

Should be prepared to signal an error of type type-error if sequence is not a proper sequence.

Notes

The :test-not argument is deprecated.

The function count-if-not is deprecated.