Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- partialFunction[func_, params__] :=
- Function[Null, func[params, ##], HoldAllComplete]
- partialFunction[func_Symbol, params__] :=
- Module[{func, cached = func},
- Options[func] = Options[cached];
- func[args___] :=
- cached[params, args];
- Format[func] =
- RawBoxes@
- BoxForm`ArrangeSummaryBox[
- "partialFunction",
- func,
- None,
- {
- cached,
- BoxForm`MakeSummaryItem[{"Args: ", Length@{params}},
- StandardForm]
- },
- {},
- StandardForm
- ];
- func~SetAttributes~HoldAllComplete;
- func
- ];
- partialFunction[func_, params__] :=
- Function[Null, func[params, ##], HoldAllComplete]
- m1 = Module[{m1 = MemoryInUse[]},
- partialFunction[Print, RandomReal[{}, {1000, 1000}]];
- m1
- ];
- MemoryInUse[] - m1
- 8006848
- ClearAll[pFun, initpFun];
- SetAttributes[pFunHold, HoldAllComplete];
- SetAttributes[initpFun, HoldAllComplete];
- initpFun[Fun_, Parameters__] :=
- pFun[<|"Function" -> Fun, "Parameters" -> pFunHold[Parameters]|>];
- pFun /: F_pFun[args___] := With[{f = F[[1]]["Function"]},
- ReleaseHold[
- Hold[f["Parameters", args]] /.
- "Parameters" -> F[[1]]["Parameters"] /. pFunHold[x_] :> x]
- ];
- pFun /: Format[
- pFun[a_Association]] := "Insert the box expression of your choice
- here."
- pf = initpFun[Print, RandomReal[{}, {10, 10} 100]]
- pf[]
Add Comment
Please, Sign In to add comment