Lisp哈希表平等测试

时间:2015-01-03 21:18:57

标签: lisp hashtable common-lisp sbcl

我用:test #'equalp创建了一个哈希表。我的钥匙是这种类型的结构

#S(KEY
        :WMES (#S(WME
                  :TYPE BLOCK
                  :NAME B1
                  :ABS-POS ((^LEFT 0) (^RIGHT 20) (^BOTTOM 0) (^TOP 5))
                  :TIME-STAMP 0)
               #S(WME
                  :TYPE BLOCK
                  :NAME B2
                  :ABS-POS ((^LEFT 15) (^RIGHT 20) (^BOTTOM 5) (^TOP 10))
                  :TIME-STAMP 0)
               #S(WME
                  :TYPE GRIPPER
                  :NAME G1
                  :ABS-POS ((^X 10) (^Y 100))
                  :TIME-STAMP 0))
        :GOALS (DUMMY-GOAL)
        :ACTIONS (DUMMY-ACTION))

当我执行(equalp <key1> <key2>)时,如果两个键在结构上相同且具有相同的内容,则该函数返回true。

相反,当我使用(gethash <key> *my-hash*)检查哈希表中的密钥时,即使存在与该密钥关联的值,该函数也会返回nil nil。任何人都可以解释为什么(equalp <key1> <key2>):test #'equalp会返回不同的结果吗?

我的Lisp实现是SBCL,我在emacs中使用slime。

我很感激帮助。

修改

以下是结构定义

(defstruct key
  (wmes '() :type list)
  (goals '() :type list)
  (actions '() :type list))

(defstruct wme
  (type '() :type symbol)
  (name '() :type symbol)
  (abs-pos '() :type list)
  (time-stamp 0 :type integer))

0 个答案:

没有答案
相关问题