CLCS
Function

position, position-if, position-if-not

position item sequence &key from-end test test-not start end key ⇒ position

position-if predicate sequence &key from-end start end key ⇒ position

position-if-not predicate sequence &key from-end start end key ⇒ position

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.
positiona bounding index of sequence, or nil.

Description

position, position-if, and position-if-not each search sequence for an element that satisfies the test.

The position returned is the index within sequence of the leftmost (if from-end is true) or of the rightmost (if from-end is false) element that satisfies the test; otherwise nil is returned. The index returned is relative to the left-hand end of the entire sequence, regardless of the value of start, end, or from-end.

Examples

 (position #\a "baobab" :from-end t) ⇒  4
 (position-if #'oddp '((1) (2) (3) (4)) :start 1 :key #'car) ⇒  2
 (position 595 '()) ⇒  NIL
 (position-if-not #'integerp '(1 2 3 4 5.0)) ⇒  4 

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 position-if-not is deprecated.