5 Debugging

5.2 Viewing files

Associated with the stack browser is the ability to view different parts of the source code corresponding to the various functions that have been called. To see this in action, create a file called, say, debug.sml, containing the following curious code defining factorial functions for odd and even numbers:

exception Fact; 
fun ofact 0 = raise Fact | ofact n = n * efact (n-1) 
and efact 0 = 1 | efact n = n * ofact (n-1); 

Now read this file from a listener with File > Use File.

The somewhat inefficiently coded functions efact and ofact happily compute factorials of even and odd integers, respectively. However, invoking one of them on an integer of the wrong parity raises an exception, and enters the stack browser. In the listener window, type

MLWorks> ofact 6;

The stack browser appears, with a list of the function calls leading up to the uncaught exception.

Figure 5.1 The MLWorks stack browser.

At the same time, a view of the file debug.sml appears in one of two ways:

Figure 5.2 The MLWorks file viewer.

In the bottom pane of the stack browser are the function calls leading to the uncaught exception; they are alternately efact and ofact. You can select any function call by clicking. Selecting a function call has two effects:


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

Generated with Harlequin WebMaker