如何解决Common LISP 中奇怪的“EVAL: undefined function T”错误
我正在用 Common Lisp 编写一个函数,但我收到了标题中提到的这个错误。
(defun sample (graph-id vertices)
(cond
((null vertices) nil)
(t
(and
(setf
(gethash (list graph-id (first vertices)) *keys*)
MOST-POSITIVE-DOUBLE-FLOAT)
(sample graph-id (rest vertices))))))
特别是,当编译器到达 (gethash (list graph-id (first vertices)) *vertex-keys*)
行时,如果我将 graph-id (first vertices)
与 (first vertices) graph-id
交换,错误就会消失。如果我使用 second
、third
或任何其他 nth
函数而不是 first
,它也会消失,我不明白它为什么会发生。
vertices
是一个类似于 (A B C D E F)
解决方法
我觉得你的问题与你如何构建哈希表*key*有关。 gethash 的工作方式是,它使用哈希表指定的 :test 函数(在 make-hash-table 调用期间给出)。
现在,假设您每次在递归中都为一个列表键设置一个值,我怀疑如果它使用默认的 make-hash-table(它使用 eql测试),因为每次您的 (gethash (list graph-id (first vertices)) *keys*) 运行时, (list ..) 调用都会创建一个永远不会与任何先前列表相等的列表。
如果您还没有,请更改您的可能:
(defvar *key* (make-hash-table))
线到类似的东西
(defvar *key* (make-hash-table :test #'equal))
事情应该会更好。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。