Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I describe a local function to (trace)?

Tags:

In common lisp, the function (trace name) can be used to see output about the calls to a function.

If my function is declared with local scope, how do I describe it to trace?

eg, how do I trace bar, below:

(defun foo (x)  
  (labels ((bar (y) (format t "bar: ~a~&" y)))  
    (bar x)))  
like image 699
John McAleely Avatar asked Apr 08 '09 14:04

John McAleely


1 Answers

As there is no standard way of tracing local functions, the way I'd go about the problem is by writing a tracing-labels macro that implements tracing, transforming 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)))
like image 156
Matthias Benkard Avatar answered Oct 12 '22 07:10

Matthias Benkard