Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inactSymbols = <||>;
- Attributes[myInactiveQ] = {HoldFirst};
- myInactiveQ[_] := False
- Attributes[myInactive] = {HoldFirst};
- myInactive[h_] := myInactive[h] = With[
- {s = Unique["inact" <> SymbolName@Unevaluated@h]},
- Attributes[s] = Complement[Attributes[h], {Protected, Locked}];
- MakeBoxes[s[args___], frm_] ^:= With[
- {b = MakeBoxes[Inactive[h][args], frm]},
- InterpretationBox[b, s[args]]
- ];
- AppendTo[inactSymbols, s -> h];
- MakeBoxes[s, frm_] ^:= MakeBoxes[myInactive[h], frm];
- myInactiveQ[s] ^= True;
- s
- ]
- myInactive[s_?myInactiveQ] := s
- myInactive[s : List | Rule] := s
- Attributes[myInactivate] = {HoldFirst};
- myInactivate[expr_] := Replace[
- Unevaluated@expr,
- {
- i : HoldPattern[myInactive[h_][args___]] :> i,
- h_Symbol[args___] :> With[
- {in = myInactive[h]},
- in[args] /; True
- ]
- },
- All
- ]
- myActivate[expr_] := expr /. inactSymbols
- a = 1;
- myInactivate[a = 2]
- (* myInactive[Set][a, 2] *)
- myActivate[%]
- (* 2 *)
- myInactivate[Sum[f[a = 2, z], {n, 1, 2}]]
- myInactivate[Sum[f[a = 2, z], {n, 1, 2}]] //
- Cases[#, _?myInactiveQ, All, Heads -> True] &
- (* {myInactive[Sum], myInactive[f], myInactive[Set]} *)
- myInactive[Set][a, 2]
Add Comment
Please, Sign In to add comment