trace(fn1, ...)
Starts tracing calls to the functions fn1, ...
. When a traced function is called, a line containing the
function and its arguments is displayed (using the function call expression syntax of the intermediate language).
The line is indented with a sequence of vertical bars which indicate the nesting depth of the function's
continuation. After the vertical bars is a greater-than sign which indicates that
the evaluation of the call is starting.
When a traced function returns a result, it is displayed with the same indentation as the call but without the greater-than sign. This makes it easy to match calls and results (the result of a given call is the value at the same indentation as the greater-than sign). If a traced function F1 performs a tail call to a traced function F2, then F2 will use the same indentation as F1. This makes it easy to spot tail calls. The special handling for tail calls is needed to preserve the space complexity of the program (i.e. tail calls are implemented even when they involve traced procedures).
When no argument is passed to trace
, a list of functions currently being traced is returned. Otherwise
returns void
.
function factorial(n)
if (n == 1) 1
else n * factorial(n-1)
trace(factorial)
factorial(6)
| > (factorial 6)
| | > (factorial 5)
| | | > (factorial 4)
| | | | > (factorial 3)
| | | | | > (factorial 2)
| | | | | | > (factorial 1)
| | | | | | 1
| | | | | 2
| | | | 6
| | | 24
| | 120
| 720
720