New answers tagged

7

In your example, a message is issued at the problem. You want to find out where the message comes from. The debugger is pretty good at this. Just enable the debugger, then enable Break at Messages, then evaluate your code. You get a nice display of the stack, which in itself allows you to localize the problem. Since this was an interactive ...


1

My code is executed in two distinct environments: inside WorkBench where I test it, and automatically by kernel. Inside WorkBench $Linked is True, so I set the following: If[$Linked, dbPrint = Print; ]; Then, when I need a debug print out, I used dbPrint which only has a value when being run inside of WorkBench, and does not effect production code. ...


3

Actually form C.E.'s comment. Make a custom function for this SetAttributes[AddPrint, HoldFirst] AddPrint[loopBody_] := Module[{st = ToString[Unevaluated[loopBody], InputForm], i = 0}, StringReplace[st, RegularExpression["^|(?<=;)"] :> TemplateApply["Print[``];", ++i]]] It can help you add Print into your loopBody automatically loopBody = ...


2

I often use the form Block[{Print=Identity}, expr] to suppress Print statements that I have added for debug purposes.


3

Since you referenced How do I evaluate only one step of an expression? I might use: (* step loaded from referenced Q&A *) mySet[str_String, val_] := step @ Symbol[str] /. _[s_Symbol] :> (s = val) Now: x = 5; mySet["x", 7]; x 7 (This also makes use of Injecting a sequence of expressions into a held expression.) For clarity the above is ...



Top 50 recent answers are included