0

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
StarBucK
  • 2,164
  • 1
  • 10
  • 33
  • 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 09: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 09:31
  • I suggest you use the debugger instead of Dialog[]. – Szabolcs May 29 '17 at 09:35
  • I used Dialog because someone advised me not to use the debugger here : https://mathematica.stackexchange.com/questions/146953/how-to-write-command-in-debug-mode/146966#146966 But I feel like mathematica has huge problem with debugging tools... – StarBucK May 29 '17 at 09:47
  • 2
    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 09:59
  • ok thank you I'll take a look :) – StarBucK May 29 '17 at 10:00
  • Replace that Dialog[] with Assert[False], open the debugging tools, check "break on assert", and run the function. When it stops, you are in a dialog. You can do everything you do in a dialog. But you will also have a stack window which displays the value of tau. – Szabolcs May 29 '17 at 10:01
  • To be clear, the debugger has a very bad reputation because it really does not work so well with breakpoints. If you avoid this feature, it is entirely usable and useful. I use it myself. But there are still a few rare problems it can cause. These are rare enough that I do not often bump into them. – Szabolcs May 29 '17 at 10:19
  • m_goldberg is correct that the debugger is not very often needed. Do check his link, and use the functions described there (Trace, etc.). I use these much more frequently than the debugger. My point is that in many cases when you would use Dialog, it is more convenient to use the debugger. You do not often need to use Dialog either ... – Szabolcs May 29 '17 at 10:20

1 Answers1

1

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.

session

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,

session

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257