User Tools


Function POSITION, POSITION-IF, POSITION-IF-NOT

Syntax

  • position item sequence &key from-end test test-not start end keyposition
  • position-if predicate sequence &key from-end start end keyposition
  • position-if-not predicate sequence &key from-end start end keyposition

Arguments and Values

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 Glossary, 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

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

Notes

The :test-not argument is deprecated.

The function position-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}