%mathpiper,def="Select"

LocalSymbols(predicate,list,result,item)
[
  Function("Select",{list,predicate})
  [
    Local(result);
    result:={};
    ForEach(item,list)
    [
      If(Apply(predicate,{item}),DestructiveAppend(result,item));
    ];
    result;
  ];
  HoldArgument("Select",predicate);
  UnFence("Select",2);
];

%/mathpiper



%mathpiper_docs,name="Select",categories="User Functions;Lists (Operations)"
*CMD Select --- select entries satisfying some predicate
*STD
*CALL
	Select(list, pred)

*PARMS

{pred} -- a predicate

{list} -- a list of elements to select from

*DESC

{Select} returns a sublist of "list" which contains all
the entries for which the predicate "pred" returns
{True} when applied to this entry.

The {Lambda} function can be used in place of a predicate function
if desired.

*E.G.

In> Select({a,b,2,c,3,d,4,e,f}, "IsInteger")
Result: {2,3,4};


/%mathpiper

list := {1,-3,2,-6,-4,3};

Select(list, Lambda({i}, i > 0 ));

/%/mathpiper

    /%output,preserve="false"
      Result: {1,2,3}
.   /%/output

*SEE Length, Find, Count, Lambda
%/mathpiper_docs