# Tag Info

40

While I wait for better answers from some very knowledgeable people in the matter on the site, I'll write what I'm thinking... I think that most of your problems are due to lack of practice with functional thinking rather than lack of debugability itself. I think one that on the contrary, one of the advantages of programming functionally is that the state ...

32

While I agree that the debugging tools could have been better developed by now, let me just throw in a few notes and links. Function chaining (f[g[h[...]]]): I'd argue that this is a good thing. Why: Functions return expressions, which are immutable. You don't introduce as much state (or at all), as in imperative languages. This makes it easier to debug ...

29

Here is my proposal for tagging messages with (the value of) an arbitrary expression at the time of message generation. The tag is placed inside the the message itself. ClearAll[withTaggedMsg] SetAttributes[withTaggedMsg, HoldAll] withTaggedMsg[exp_, label_: "When"] := Function[, InternalInheritedBlock[{MessagePacket}, Unprotect @ MessagePacket;...

28

Like in other programming languages, such as C or Java, assertions are used to catch errors in the logic of your code. With discipline, you can also use exceptions for a similar purpose (see e.g. this discussion for an example). Using patterns and returning a function unevaluated is useful in different types of situations. The linked above answer also ...

27

Preamble It is hard to say what exactly is causing this without seeing the code, but, assuming that there are no memory leaks in the built-in functions you are using, I am only aware of a very few possible causes for memory leaks in Mathematica. Since almost anything is immutable, the leaks must be associated with some symbols for which definitions are ...

26

Here is a function findBadSets that will find any explicitly bad Set/SetDelayed attempts in a given expression. Simply wrap it around a syntactically complete block of code, or follow the block with // findBadSets and the errors are printed one per row, protected symbol followed by complete left-hand side for each bad Set: (* your example *) // findBadSets ...

21

I found a curious style of debugging that I call "Epicsauce Debugging Level 2." First you type this: x = 0; While[True, Pause[1]; (*Dynamic[x]*) x++ ]; Then you highlight the Dynamic[x] and press Ctrl+Shift+Enter. Then you execute the cell and BE AMAZED!!! It's quite hilarious, but I wonder how useful it would be for more serious code. I've already ...

20

(It's interesting I asked a similar question before. As your question is a superset of mine, I would like to post the answer here.) About the first question: How does the debugger know what to highlight? I don't really know the internal mechanism, but I hope this answer can provide some possible tiny clues. About the second question: Can we influence this ...

19

There are indeed some open source alternatives, as other posters have suggested, but you will miss the unique facilities of WB to develop state of the art documentation. So if you want to develop some serious work in MMA, for yourself or others, you should seriously consider WB. Having said that, I use WB in a (probably) unconventional way. Within WB you can ...

18

I cannot seem to make it do exactly what you want do to how messages are created, but here is a serviceable alternative using $MessagePrePrint.$MessagePrePrint formats the variables specified in the message string, and in your example, the message has the form General::indet = "Indeterminate expression 1 encountered." where the 1 will be replaced by ...

18

Let me first answer your second question, since I can only guess about the main question: I also observed that the syntax colouring (version 10, windows 7) suggests that Trace can be used with only two arguments. It's really just the coloring that goes wrong and has nothing to do with functionality. You can see that it is not even related to ...

18

Normally I like to use On and Off for this kind of tracing as it is easy to set up without modifying any symbols. However, it does not immediately work in this case: On[Roots] Solve[x^3 - 2 x + 12 == 0, x]; Off[] This does not produce any trace messages. Something must be using Quiet to suppress them. We can check this hypothesis: On[Quiet] Solve[x^3 -...

18

You can contact Wolfram Tech Support through this form: http://www.wolfram.com/support/contact/email/?topic=Feedback or by sending an email to support@wolfram.com Please always report bugs you find to Wolfram Technical Support. Some people will post bugs to this StackExchange site. Please do not do this. It is okay to ask about workarounds to bugs ...

17

There's absolutely no need to load a package if all you want to do is simple Gauss-Legendre quadrature: GaussLegendreQuadrature[f_, {x_, a_, b_}, n_Integer: 10, prec_: MachinePrecision] := Module[{nodes, weights}, {nodes, weights} = Most[NIntegrateGaussRuleData[n, prec]]; (b - a) weights.Map[Function[x, f], Rescale[nodes, {0, 1}, {a, b}]...

16

There is also a TextMate bundle for Mathematica: https://github.com/dehowell/mathematica-tmbundle TextMate is for Mac only, but this bundle work in other editors like Sublime Text (multi platform) (windows) Also for Atom (multi platform) there is this: https://github.com/Fitzse/language-mathematica

16

Update: The very likely reason for the garbled error messages is that you have a Chinese version of Visual Studio printing errors in Chinese, and there is a mismatch in the character encoding of these messages and how Mathematica tried to interpret them. CreateLibrary has two very useful options: "ShellCommandFunction" and "ShellOutputFunction". Set ...

15

QuantityForm (and some other formatting functions) issues messages at typesetting instead of evaluation, and Trace is generating output that is in an unevaluated state, which QuantityForm isn't expecting. Here's a couple of similar examples: Trace[Block[{form = "LongForm"}, QuantityForm[Quantity[1, "Meters"], form]]] Trace[Block[{digits = 3}, NumberForm[N[...

14

rcollyer has a nice solution. Here's another possibility using Check and printing the list of messages generated at the current evaluation. Quiet@Block[{$OldMessages = 0}, Do[Check[#^#/# &@Mod[i, 2], Print@StringForm["At i=, ", i,$MessageList[[$OldMessages + 1 ;;]]];$OldMessages = Length@$MessageList;], ... 14 This version of ShowIt first shown by Leonid Shifrin is particularly useful, it can be used in conjunction with the function ReapTags[] defined below also. It now uses the LetL[] function also from Leonid defined here (in order to avoid a nested With for printedExpr). I've incorporated the answer of Szabolcs to the question Is it possible to Print ... 12 You can enter arbitrary expressions in the Expressions debugging view: The function VariableValue must be used in such expressions in order to access any active variables. If the Expressions view is not visible, you can open it from the Workbench main menu using Window / Show View... / Expressions. 12 There is a certain impedance mismatch between lines of code and Mathematica expressions, because Mathematica code is written more or less directly in the parse trees, and the syntax (which encourages nested expressions) was not particularly designed to make lines a really good concept here. That said, this would be a problem in any language, to various ... 12 My first instinct in such cases is usually to use Trace to figure out which part of the evaluation is behaving differently from what I expect. For the example you already have this point isolated. Then I typically try to dissect it and determine why it misbehaves. An important part of this dissection is using FullForm to remove all the shorthands that are ... 12 In the original article there is a semi-colon after the final Show in tile. Remove that semi-colon and the program should run normally. While you're at it, replace GraphicsArray with GraphicsGrid. You probably also noted that the article uses unusual color names that Mathematica does not recognize. (The package, Graphics Colors is not found.) You will need ... 11 This is a memory leak in HistogramList: You can reclaim the memory by evaluating Remove["*`*modelData$*"]

11

This is admittedly messy, but something along these lines might work: insertBelowEvaluationCell[expr_] := (SelectionMove[EvaluationNotebook[], After, EvaluationCell]; NotebookWrite[EvaluationNotebook[], Cell[BoxData@ToBoxes[expr], "Print"]]) This function moves the insertion point just below the evaluation cell before inserting the text or ...

11

Implementation Here is a better version of my debug function posted here, which would print the stack on the first message generated, and abort the computation. I have used it extensively with great effect in many cases. This constructs the nested OpenerView from an arbitrary expression: ClearAll[openerDress]; SetAttributes[openerDress, HoldAll]; ...

10

One can use Trace for this. I stuck in an extra, different error to show it is omitted in the output. It should also be clear how to trace other error messages. foo = Trace[ Table[ a = 1/0; b = {2, 3} c = i;, {i, 2}], HoldPattern@Message[Set::write, ___], TraceAbove -> True] (* Power::infty, Set::write errors *) If you would ...

10

Why complicate it? a[[3 ;; 4, 2 ;; 4]] = b; Here is a general function. It take a main matrix, and a sub matrix. It puts the sub matrix inside the main matrix. All what you have to do is just tell it the starting row number and starting column number for where to insert the sub matrix at. Updated: Added pattern checking on arguments. Added additional ...

10

The debugger in Mathematica is, in fact, a bit hard to use. However, it is functional. To create a breakpoint, one must select the WHOLE command. Just double clicking on the command name will do. Then you press the "Break at Selection" button in the debugger control panel. I still have no clear understanding what is considered a whole command from the ...

Only top voted, non community-wiki answers of a minimum length are eligible