Within the debugger, can we watch local variables within a Module?

As the screenshot shows, the “i” only display its global value (12) upon a message breakpoint. Is there a way to show its local value? enter image description here


i = 12; f[] := Module[{i}, For[i = 1, i < 10, i++, Print[i]; Print[":\t"]; Print[i/0]]; ];



  • 2
    $\begingroup$ Hummm... I would say that Mathematica debugger is not a good option for debug. I hope that the new Wolfram Language could came with a new Wolfram Debugger. :p $\endgroup$
    – Murta
    Jan 4, 2014 at 20:14
  • 1
    $\begingroup$ It is not showing the local value because it is not really i within the module - it's some temporary variable. $\endgroup$
    – VF1
    Jan 4, 2014 at 20:17
  • $\begingroup$ @vf1: Do you know how to get the actual name of the temporary variable so we can watch them, like in Visual studio? $\endgroup$
    – JimmyLin
    Jan 4, 2014 at 20:18
  • $\begingroup$ @Murta: link, user Szabolcs metioned that the debugger is "immensely helpful" because it can watch local variable. Any idea on how he achieved that? $\endgroup$
    – JimmyLin
    Jan 4, 2014 at 20:19
  • $\begingroup$ @Murta: the previous link was wrong, please see this $\endgroup$
    – JimmyLin
    Jan 4, 2014 at 20:22

1 Answer 1



I figured it out - never used the debugger in MMA before so that's why I improvised. The Stack window has a "Local variables" tab - just open that: enter image description here

Old answer

You can get the actual temporary name of the variable by printing it before it has a value. I'll see if there's a nicer solution.

enter image description here

  • $\begingroup$ This is however not sufficient. For example, what if "i" is the index of an array and we want to display value of myArray[i]? The small expandable "Local variable" icon shows only the value, but that value cannot be used. $\endgroup$
    – JimmyLin
    Jan 4, 2014 at 20:39
  • $\begingroup$ @JimmyLin your question states "Is there a way to show its local value?" - for the time being, you can copy and paste. If you're looking for a Visual Studio level of debugging, I recommend Wolfram Workbench. $\endgroup$
    – VF1
    Jan 4, 2014 at 20:43
  • $\begingroup$ @JimmyLin even copy/paste is unnecessary - you can directly edit the local variables cell. $\endgroup$
    – VF1
    Jan 4, 2014 at 20:46
  • $\begingroup$ If you change "Module" to "Block", could you notice any difference? On my machine now I can access (both view and edit) the local variable. $\endgroup$
    – JimmyLin
    Jan 4, 2014 at 23:08
  • $\begingroup$ Could you show the command to print local variable "i"'s name "i$xxx"? I find it useful, but seems you have replaced the old answer with the newer one. $\endgroup$
    – JimmyLin
    Jan 4, 2014 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.