5 Debugging
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
.
Generated with Harlequin WebMaker