[英]Weird “EVAL: undefined function T” error in Common LISP
I'm writing a function in Common Lisp, but I'm getting this error I mentioned in the title.我在 Common Lisp 中写了一个 function,但是我收到了我在标题中提到的这个错误。
(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))))))
In particular, when the compiler reaches the (gethash (list graph-id (first vertices)) *vertex-keys*)
line, if I swap graph-id (first vertices)
with (first vertices) graph-id
, the error disappears.特别是,当编译器到达
(gethash (list graph-id (first vertices)) *vertex-keys*)
行时,如果我将graph-id (first vertices)
与(first vertices) graph-id
交换,错误就会消失. It also disappears if I use second
, third
or any other nth
functions rather than first
, I can't understand why it happens.如果我使用
second
, third
或任何其他nth
函数而不是first
,它也会消失,我不明白为什么会发生。 vertices
is a list like (AB C DEF)
vertices
是一个类似(AB C DEF)
的列表
I feel like your problem is related to how you construct the hash table *key*.我觉得您的问题与您如何构建 hash 表 *key* 有关。 The way gethash works is, it uses the hash table's designated:test function (given during make-hash-table call).
gethash 的工作方式是,它使用 hash 表的指定:test function(在 make-hash-table 调用期间给出)。
Now, given that you're setting a value to a key that's a list each time in the recursion, I doubt you'll add anything to your hash table if it uses default make-hash-table (which uses eql for testing), because each time your (gethash (list graph-id (first vertices)) *keys*) runs, the (list..) call creates a list that's never eql to any previous list.现在,假设您在递归中每次都为一个列表键设置一个值,我怀疑如果它使用默认的 make-hash-table (使用 eql 进行测试),您是否会向 hash 表添加任何内容,因为每次您的 (gethash (list graph-id (first vertices)) *keys*) 运行时, (list..) 调用都会创建一个与任何先前列表都不相等的列表。
If you haven't already, change your possibly:如果您还没有,请更改您的可能:
(defvar *key* (make-hash-table))
line to something like像这样的东西
(defvar *key* (make-hash-table :test #'equal))
and things should work better.事情应该会更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.