2 @c This is part of the GNU Guile Reference Manual.
3 @c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007
4 @c Free Software Foundation, Inc.
5 @c See the file guile.texi for copying conditions.
11 The @code{(ice-9 debug)} module implements tracing of procedure
12 applications. When a procedure is @dfn{traced}, it means that every
13 call to that procedure is reported to the user during a program run.
14 The idea is that you can mark a collection of procedures for tracing,
15 and Guile will subsequently print out a line of the form
18 | | [@var{procedure} @var{args} @dots{}]
21 whenever a marked procedure is about to be applied to its arguments.
22 This can help a programmer determine whether a function is being called
23 at the wrong time or with the wrong set of arguments.
25 In addition, the indentation of the output is useful for demonstrating
26 how the traced applications are or are not tail recursive with respect
27 to each other. Thus, a trace of a non-tail recursive factorial
28 implementation looks like this:
43 While a typical tail recursive implementation would look more like this:
55 @deffn {Scheme Procedure} trace procedure
56 Enable tracing for @code{procedure}. While a program is being run,
57 Guile will print a brief report at each call to a traced procedure,
58 advising the user which procedure was called and the arguments that were
62 @deffn {Scheme Procedure} untrace procedure
63 Disable tracing for @code{procedure}.
66 Here is another example:
72 (append (rev (cdr ls))
73 (cons (car ls) '())))) @result{} rev
75 (trace rev) @result{} (rev)
78 @result{} [rev (a b c d e)]
93 Note the way Guile indents the output, illustrating the depth of
94 execution at each procedure call. This can be used to demonstrate, for
95 example, that Guile implements self-tail-recursion properly:
102 (cons (car ls) sl)))) @result{} rev
104 (trace rev) @result{} (rev)
106 (rev '(a b c d e) '())
107 @result{} [rev (a b c d e) ()]
117 Since the tail call is effectively optimized to a @code{goto} statement,
118 there is no need for Guile to create a new stack frame for each
119 iteration. Tracing reveals this optimization in operation.
123 @c TeX-master: "guile.texi"