%mathpiper,def="Find"

Function("Find",{list,element})
[
  Local(result,count);
  Bind(result, -1);
  Bind(count, 1);
  While(And(result<0, Not(IsEqual(list, {}))))
  [
    If(IsEqual(First(list), element),
      Bind(result, count)
      );
    Bind(list,Rest(list));
    Bind(count,AddN(count,1));
  ];
  result;
];

%/mathpiper



%mathpiper_docs,name="Find",categories="User Functions;Lists (Operations)"
*CMD Find --- get the index at which a certain element occurs
*STD
*CALL
	Find(list, expr)

*PARMS

{list} -- the list to examine

{expr} -- expression to look for in "list"

*DESC

This commands returns the index at which the expression "expr"
occurs in "list". If "expr" occurs more than once, the lowest
index is returned. If "expr" does not occur at all,
{-1} is returned.

*E.G.

In> Find({a,b,c,d,e,f}, d);
Result: 4;
In> Find({1,2,3,2,1}, 2);
Result: 2;
In> Find({1,2,3,2,1}, 4);
Result: -1;

*SEE Contains
%/mathpiper_docs