User Tools


Function COUNT, COUNT-IF, COUNT-IF-NOT

Syntax

  • count item sequence &key from-end start end key test test-notn
  • count-if predicate sequence &key from-end start end keyn
  • count-if-not predicate sequence &key from-end start end keyn

Arguments and Values

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

Side Effects

None.

Affected By

None.

Exceptional Situations

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

See Also

  • {\secref\TestFunctionRules}
  • {\secref\TraversalRules}

Notes

The :test-not argument is deprecated.

The function count-if-not is deprecated.

\issue{TEST-NOT-IF-NOT:FLUSH-ALL} \issue{SUBSEQ-OUT-OF-BOUNDS} \issue{RANGE-OF-START-AND-END-PARAMETERS:INTEGER-AND-INTEGER-NIL} \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE} \issue{TEST-NOT-IF-NOT:FLUSH-ALL}