对非我定义的函数使用跟踪

Using trace with functions not defined by me

我使用的是 sbcl 1.4.6,我有这样的行为:

*  (trace string<)

(STRING<)
*  (string< "hola" "pato")
  0: (STRING< "hola" "pato")
  0: STRING< returned 0
0
*  (defun test-without-cond (str)
           (string< "hola" str))

TEST-WITHOUT-COND
* (test-without-cond "pato")

0

如果函数已经在common lisp 中定义,在用户定义的函数内部使用时我不能使用trace。但是如果我定义函数

,这不是问题
* (defun my-string< (str) (string< str "hello"))
MY-STRING<

* (trace my-string<)

(MY-STRING<)

* (defun test-2 (str) (my-string< str))

TEST-2
* (test-2 "gato")
  0: (MY-STRING< "gato")
  0: MY-STRING< returned 0
0

为什么会这样?

可以跟踪的内容取决于实施和各种设置。

对于 SBCL,请阅读手册:Open Coding and Inline Expansion

但是 SBCL 现在也有一个解释器,看起来您可以从解释的代码中跟踪对 CL 函数的调用:

* (setf  *evaluator-mode* :interpret)

:INTERPRET
* (trace string<)

(STRING<)
* (defun test-without-cond (str)
    (string< "hola" str))

TEST-WITHOUT-COND
* (test-without-cond "pato")
  0: (STRING< "hola" "pato")
  0: STRING< returned 0
0
* 

请注意,跟踪核心函数可能需要小心,因为它们可以被调用很多...