

Function("Substitute",{body,predicate,change})
[
  Substitute(body);
];
HoldArg("Substitute",predicate);
HoldArg("Substitute",change);
UnFence("Substitute",3);
RuleBase("Substitute",{body});
UnFence("Substitute",1);

Rule("Substitute",1,1,Apply(predicate,{body}) = True)
[
  Apply(change,{body});
];
Rule("Substitute",1,2,IsFunction(body))
[
  Apply("MapArgs",{body,"Substitute"});
];
Rule("Substitute",1,3,True) body;

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