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

自闭症网瘾萝莉.ら 提交于 2019-12-01 07:36:46

Tracing local functions with (TRACE ...) is not defined by ANSI Common Lisp.

Some implementations have extensions to do that. See for example CMU CL.

Other than that, you would need add some code to the definition of FOO. 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 would expand into code that prints the entry and exit.

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)))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!