%mathpiper,def="Contains"

Function("Contains",{list,element})
[
  Local(result);
  Bind(result,False);
  While(And(Not(result), Not(IsEqual(list, {}))))
  [
    If(IsEqual(First(list),element),
      Bind(result, True),
      Bind(list, Rest(list))
      );
  ];
  result;
];

%/mathpiper



%mathpiper_docs,name="Contains",categories="User Functions;Lists (Operations)"
*CMD Contains --- test whether a list contains a certain element
*STD
*CALL
	Contains(list, expr)

*PARMS

{list} -- list to examine

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

*DESC

This command tests whether "list" contains the expression "expr"
as an entry. It returns {True} if it does and
{False} otherwise. Only the top level of "list" is
examined. The parameter "list" may also be a general expression, in
that case the top-level operands are tested for the occurrence of
"expr".

*E.G.

In> Contains({a,b,c,d}, b);
Result: True;
In> Contains({a,b,c,d}, x);
Result: False;
In> Contains({a,{1,2,3},z}, 1);
Result: False;
In> Contains(a*b, b);
Result: True;

*SEE Find, Count
%/mathpiper_docs