Node: Searching Sequences, Next: , Previous: Modifying Sequences, Up: Sequences



Searching Sequences

position obj seq Function

position obj seq start Function

position obj seq start end Function

positionL obj seq Function

positionL obj seq start Function

positionL obj seq start end Function

position returns the position of the first object found in the sequence seq that is eql to the given object obj. If the object is not found in the sequence then a -1 is returned. The positionL functions are the same but an Lpp Integer object is returned for the position and nil is returned if the object is not found. The optional start argument is a positive integer as either an int or Lpp Integer object and indicates at what position to start the search. The optional end argument is also a similar positive integer and it indicates at what position to end the search. In this case the search is from start to one element before end. The end argument can also be nil defaulting end to be the length of the sequence, which would cause a search to the end of the sequence.

positionTest obj seq test Function

positionTest obj seq test start Function

positionTest obj seq test start end Function

positionTestL obj seq test Function

positionTestL obj seq test start Function

positionTestL obj seq test start end Function

The positionTest and positionTestL functions are exactly the same as the position and positionL functions except that instead of testing for the object obj in the sequence using eql the function test is used. test must be a function of two arguments the first being the object obj and the second an element of the sequence seq and must return non-nil for when an object satisfies the test.

Here are some examples

     let string1 = L("abcabc");
     position(L('a'), string1) => 0
     position(L('c'), string1) => 2
     position(L('a'), string1, 1) => 3
     positionL(L('a'), string1, 1, 3) => nil
     
     let list1 = list(L(1), L(2), L("three"), L(4));
     position(L(4), list1) => 3
     position(L("three"), list1) => -1
     positionL(L("three"), list1) => nil
     positionTest(L("three"), list1, L(equal)) => 2