问题描述
我正在尝试通过 Touretzky 撰写的“Common LISP a Gentle Introduction to Symbolic computation”一书来学习 lisp。书中有一个实用程序,Dtrace(我使用 dtrace.generic)。使用 dtrace 的示例:
(defun add-to-end (x y)
(append x (list y)))
(defun repeat-first (phrase)
(add-to-end phrase (first phrase)))
> (dtrace add-to-end repeat-first)
(ADD-TO-END REPEAT-FirsT)
> (repeat-first ’(for whom the bell tolls))
----Enter REPEAT-FirsT
| PHRASE = (FOR WHOM THE BELL TOLLS)
| ----Enter ADD-TO-END
| | X = (FOR WHOM THE BELL TOLLS)
| | Y = FOR
| \--ADD-TO-END returned
| (FOR WHOM THE BELL TOLLS FOR)
\--REPEAT-FirsT returned
(FOR WHOM THE BELL TOLLS FOR)
(FOR WHOM THE BELL TOLLS FOR)
不幸的是在 Clozure(在 Win7 上)结果是:
? (repeat-first '(for whom the bell tolls))
----Enter REPEAT-FirsT
| Arg-1 = (FOR WHOM THE BELL TOLLS)
| ----Enter ADD-TO-END
| | Arg-1 = (FOR WHOM THE BELL TOLLS)
| | Arg-2 = FOR
| \--ADD-TO-END returned (FOR WHOM THE BELL TOLLS FOR)
\--REPEAT-FirsT returned (FOR WHOM THE BELL TOLLS FOR)
(FOR WHOM THE BELL TOLLS FOR)
函数参数名称丢失。它应该依赖于 fetch-arglist 函数。基于这个 answer,我将 fetch-arglist 写成:
(defun fetch-arglist (x) (arglist x))
事实上:
? (arglist #'add-to-end)
(X Y)
:ANALYSIS
不幸的是,结果是一样的。在 Clozure 中,有没有办法让函数的参数名称出现在 dtrace 中?
更新: 解决方案是(在 dtrace.generic 中):
(defun fetch-arglist (x) (ccl:arglist x))
更新 2: dtrace 将奇怪的结果打印为:
((CCC (? AAA . #1=(0)) (? BBB . #1#)))
虽然 Clozure 的痕迹打印正确:
((CCC (? AAA 0) (? BBB 0)))
Update3(希望是最后一次): 由于 Vsevolod Dyomkin 的解决方案:
(defparameter *dtrace-print-circle* nil)
*print-circle*
显示 common substructure:
CL-USER> (setf *print-circle* t)
T
CL-USER> (let ((l '((a b c) (d e f))))
(list l (copy-list l)))
;=> ((#1=(A B C) #2=(D E F)) (#1# #2#))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)