/usr/share/yacas/scripts/substitute.rep/code.ys is in yacas 1.3.6-2+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 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;
/*Extremely hacky workaround, MacroSubstitute is actually the same as Substitute,
but without re-evaluating its arguments. I could not just change Substitute, as
it changed behaviour such that tests started to break.
*/
Function("MacroSubstitute",{body,predicate,change})
[
`MacroSubstitute((Hold(@body)));
];
HoldArg("MacroSubstitute",predicate);
HoldArg("MacroSubstitute",change);
UnFence("MacroSubstitute",3);
RuleBase("MacroSubstitute",{body});
UnFence("MacroSubstitute",1);
Rule("MacroSubstitute",1,1,`ApplyPure(predicate,{Hold(Hold(@body))}) = True)
[
`ApplyPure(change,{Hold(Hold(@body))});
];
Rule("MacroSubstitute",1,2,`IsFunction(Hold(@body)))
[
`ApplyPure("MacroMapArgs",{Hold(Hold(@body)),"MacroSubstitute"});
];
Rule("MacroSubstitute",1,3,True)
[
`Hold(@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);
];
|