Usage
find(t, l)
Signature
find: (T, %) (%, MachineInteger)
Parameter | Type | Description |
---|---|---|
t | T | the value to search for |
l | % | a list |
Returns
Returns (b, i) such that:
The list a does not need to be sorted, and the complexity is expected to be linear in its size.
Remarks
No copy of l is made: if b is not empty, then its data is shared with l. This function allows all the occurences of t to be found successively in a list, as in the example below.
Example
If l1 is the list of MachineInteger [1,6,2,5,3,7,2,4], then (l2, n) := find(2, l1) sets l2 to [2,5,3,7,2,4] and n to 3, the further call (l3, n) := find(2, rest l2) sets l3 to [2,4] and n to 4, and the further call (l4, n) := find(2, rest l3) sets l4 to empty.