How to describe a local function (trace)?

In general, a lisp function (trace name) can be used to view the output of function calls.

If my function is declared with a local scope, how can I describe it for tracing?

For example, how can I track the panel below:

(defun foo (x) (labels ((bar (y) (format t "bar: ~a~&" y))) (bar x))) 
+4
source share
2 answers

Tracking local functions using (TRACE ...) not defined by ANSI Common Lisp.

Some implementations have extensions for this. See for example CMU CL .

Other than that, you need to add some code to the FOO definition. For example, it might be useful to have a macro so that you can write the call to bar as (trace-it (bar x)), and the macro will expand into code that prints the record and exits.

+2
source

Since there is no standard way to track local functions, the way I ran into the problem is to write a tracing-labels macro that implements tracing by converting the following:

 (defun foo (x) (tracing-labels ((bar (y) (format t "bar: ~a~&" y))) (bar x))) 

into something like this:

 (defun foo (x) (labels ((bar (y) (format *trace-output* "~&ENTER: ~S" 'bar) ;' (multiple-value-prog1 (progn (format t "bar: ~a~&" y)) (format *trace-output* "~&LEAVE: ~S" 'bar)))) ;' (bar x))) 
+3
source

All Articles