chickadee » srfi-1 » list-index

list-index pred clist_1 clist_2 ...procedure

Return the index of the leftmost element that satisfies PRED.

If there are N list arguments CLIST_1 ... CLIST_N, then PRED must be a function taking N arguments and returning a boolean result.

list-index applies PRED to the first elements of the CLIST_I parameters. If this application returns true, list-index immediately returns zero. Otherwise, it iterates, applying PRED to the second elements of the CLIST_I parameters, then the third, and so forth. When it finds a tuple of list elements that cause PRED to return true, it stops and returns the zero-based index of that position in the lists.

The iteration stops when one of the lists runs out of values; in this case, list-index returns #f.

(list-index even? '(3 1 4 1 5 9)) => 2
(list-index < '(3 1 4 1 5 9 2 5 6) '(2 7 1 8 2)) => 1
(list-index = '(3 1 4 1 5 9 2 5 6) '(2 7 1 8 2)) => #f