New answers tagged

3

We can (ab)use the automatic expansion of OptionValue into its three-argument-form, which works even inside rules: Options[func] = {"opt" -> None}; {func["opt" -> 1], func[]} /. func[OptionsPattern[]] :> OptionValue["opt"] (* {1, None} *) Now, for your example: First, we define iExpandOptionValue that takes expands ...


5

It's pretty simple: you just make sure that the function pattern never matches illegal arguments. For example: ClearAll[f] f[a_ /; a != 0] := 1; f[0] f[2] f[0] 1 Sometimes you also want to do something (like issue a message) before returning the expression unevaluated. You can do this by adding to following definition to f (don't clear the previous ...


1

I'd use Mr.Wizard's step[] function for the most generality. (* https://mathematica.stackexchange.com/a/1447 *) step // ClearAll; SetAttributes[step, HoldAll] step[expr_] := Module[{P}, P = (P = Return[#, TraceScan] &) &; TraceScan[P, expr, TraceDepth -> 1]]; setParameters // ClearAll; SetAttributes[setParameters, HoldAll]; setParameters[...


2

Here is another implementation of joebolte's TraceView using the new Tree functionality in 12.3: SetAttributes[TraceView, HoldFirst]; TraceView[expr_] := Module[{trace, f, h, tree}, trace = Trace[expr, TraceOriginal -> True]; f[steps_List] := Rest[steps]; f[step_] := {}; h[steps_List] := First[steps]; h[step_] := step; tree = NestTree[f, trace,...


4

The current status of this answer I intend to return back to this very exciting question with a better answer, when I have it, but for now there will be something here to get you started. General aspects of WL DSL creation The main steps in creating a WL DSL There are a few steps in WL DSL creation which seem to be universal and applicable to most cases: ...


Top 50 recent answers are included