Next: Trapping Errors
Up: Tracing and the Print
Previous: printlevel
trace
The trace can be used in conjunction with the option
command in Darwin(see §
) or it can be used as a
Darwin command directly by passing a name of a procedure as
a parameter. When applied to procedures, the trace command
directs Darwin to display the result of every executed statement
accompanied with the value of the parameters at the entry point to the
routine and the value being returned.
The option trace combination
must follow any local and global variable declarations after the
routine declaration.
> Sum := proc(val : real)
> local total;
> option trace;
> # must follow local and global variable declarations
>
> total:=0;
> for i from 1 to val do
> total :=total+i;
> od;
> total;
> end;
> Sum(5);
{--> enter Sum, args = 5
total := 0
total := 1
total := 3
total := 6
total := 10
total := 15
15
<-- exit Sum = 15}
15
Alternatively, we could omit the option trace command and invoke
trace as follows.
> Sum := proc( val : real )
> local total;
>
> total:=0;
> for i from 1 to val do
> total :=total+i;
> od;
> total;
> end;
> trace(Sum);
> Sum(5)
Gaston Gonnet
1998-09-15