%mathpiper,def="Substitute"

Function("Substitute",{body,predicate,change})
[
  Substitute(body);
];
HoldArgument("Substitute",predicate);
HoldArgument("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;

%/mathpiper