It is sometimes useful to know where in a list a certain element occurs, if it occurs at all. Program the function index-in-list-by-predicate which searches for a given element. The comparion between the given element and the elements in the list is controlled by a comparison parameter to index-in-list-by-predicate. The function should return the list position of the match (first element is number 0), or #f if no match is found.
Some examples will help us understand the function:
(index-in-list-by-predicate '(a b c c b a) 'c eq?) => 2 (index-in-list-by-predicate '(a b c c b a) 'x eq?) => #f (index-in-list-by-predicate '(two 2 "two") 2 (lambda (x y) (and (number? x) (number? y) (= x y)))) => 1
Be aware if your function is tail recursive.