5 Debugging

5.6 Local variables

As well as showing the sequence of function calls and their arguments, the stack browser shows the values of local variables in force during a function call. You can see this in action by typing the following function definition into the listener:

fun f[] = raise Div | f(h::t) = let val y:int = h*h in y+f t end;

The function f is supposed to calculate the sum of squares of a list of integers, but will fail because it raises an exception on the empty list. Now evaluate f[3,4]. The stack browser appears, showing a stack of three function calls. If you select, say, the middle of these, MLWorks shows all the local variables in force during that function call.

Figure 5.5 Local variables in the stack browser.

It shows that, during the call to f[4], h and t (defined by pattern-matching) had the values 4 and [], respectively, and y (defined explicitly using let) had the value 16.


MLWorks User Guide (UNIX version 1.0) - 3 DEC 1996

Generated with Harlequin WebMaker