# Using Dialog inside a function to debug

I need to understand why my functions doesn't work.

Thus, I have put a Dialog at the beginning of it :

fonction38lhs[tau_]:=
Module[{q},
Dialog[]
q = Exp[2 tau];
(SixJSymbolqDef[{j1, j2, j3}, {j4, j5, j6}, q] -
SixJSymbol[{j1, j2, j3}, {j4, j5, j6}]) -
((2*tau)^2 (1/6))
((1/4) Sum[j[[i]] (j[[i]] + 1), {i, 1, 6}]
SixJSymbol[{j1, j2, j3}, {j4, j5, j6}] +
Triple[j1, j2, j3, j4, j5, j6])]


The behavior of my function doesn't really matter.

When I evaluate fonction38lhs[0.8], my program freezes because of the dialog and I am able to evaluated commands. But if I want to display the value of tau, it says it is an unknown variable.

To say it differently, my dialog seems to occur out of the function and not inside. Indeed I can show variables of the notebook outside of the function.

How can I gain access to local variable inside of the function within a dialog session?

• tau is not a variable. It is a pattern name. Its value gets substituted directly, without ever assigning a value to the symbol tau. – Szabolcs May 29 '17 at 9:26
• When I pass argument to functions I will not be able to check their values inside of the function for example ? – StarBucK May 29 '17 at 9:31
• I suggest you use the debugger instead of Dialog[]. – Szabolcs May 29 '17 at 9:35
• I used Dialog because someone advised me not to use the debugger here : mathematica.stackexchange.com/questions/146953/… But I feel like mathematica has huge problem with debugging tools... – StarBucK May 29 '17 at 9:47
• Well, I advise you to use the debugger, but do it the way I described it in the answer I linked. Do not try to set any breakpoints using the GUI and you'll be fine. – Szabolcs May 29 '17 at 9:59

Inside your function tau is just a number. It does't exist as a variable. To do what you want, you have to introduce an auxiliary variable, say t.

Then you can have session like.

Notes:

• Out[154], 8.38906, did not appear until (Dialog) In[157] was evaluated.
• The returned value of t was used to compute q.
• Out[157] confirms that t was changed at top-level and that the value returned from fonction38lhs is equal to 1 + Exp[2 t] as it should be.

### Update

Another possibility for interacting with tau goes like this,

If you supply tau to Dialog, it becomes available in the dialog session as %.