Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

Clear[i];

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

f[]

Jimmy

share|improve this question
2  
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 –  Murta Jan 4 at 20:14
1  
It is not showing the local value because it is not really i within the module - it's some temporary variable. –  VF1 Jan 4 at 20:17
    
@vf1: Do you know how to get the actual name of the temporary variable so we can watch them, like in Visual studio? –  JimmyLin Jan 4 at 20:18
    
@Murta: link, user Szabolcs metioned that the debugger is "immensely helpful" because it can watch local variable. Any idea on how he achieved that? –  JimmyLin Jan 4 at 20:19
    
@Murta: the previous link was wrong, please see this –  JimmyLin Jan 4 at 20:22

1 Answer 1

Edit

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

share|improve this answer
    
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. –  JimmyLin Jan 4 at 20:39
    
@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. –  VF1 Jan 4 at 20:43
    
@JimmyLin even copy/paste is unnecessary - you can directly edit the local variables cell. –  VF1 Jan 4 at 20:46
    
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. –  JimmyLin Jan 4 at 23:08
    
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. –  JimmyLin Jan 4 at 23:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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