如果在Lisp中没有定义超类状态,这意味着什么?

Mic*_*lle 0 class common-lisp clos superclass

我的超类定义如下:

(defclass missionary-state (state)
  ((missionary-left :initarg :missionary-left :initform nil :accessor missionary-left
    :documentation "the number of missionaries on the left side of the river")
   (missionary-right :initarg :missionary-right :initform nil :accessor missionary-right
    :documentation "the number of missionaries on the right side of the river")
   (cannibal-left :initarg :cannibal-left :initform nil :accessor cannibal-left
    :documentation "the number of cannibals on the left side of the river")
   (cannibal-right :initarg :cannibal-right :initform nil :accessor cannibal-right
     :documentation "the number of cannibals on the right side of the river")
   (boat-pos :initarg :boat-pos :initform nil :accessor boat-pos 
    :documentation "the side the boat is on")))
Run Code Online (Sandbox Code Playgroud)

这是我尝试加载后得到的错误消息:

Error: Class #<STANDARD-CLASS MISSIONARY-STATE>
       can't be finalized because superclass STATE
       is not defined yet
Run Code Online (Sandbox Code Playgroud)

Syl*_*ter 5

从文档中defclass可以看出,您是missionary-state通过扩展父类来创建的state.

现在,错误消息指示您missionary-state在定义missionary-state父类之前尝试创建实例state.它不是标准类,因此您需要告诉系统它是什么.

如果您不打算这样做,state那么只需删除定义中的父类:

(defclass missionary-state ()
  ...)
Run Code Online (Sandbox Code Playgroud)

现在,这是一个直接的子类的standard-objectstandard-class.