Search code examples
classcommon-lispsuperclassclos

What does it mean if a superclass state is not defined in Lisp?


My superclass is defined as follows:

(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")))

This is the error message that I get after trying to loading it:

Error: Class #<STANDARD-CLASS MISSIONARY-STATE>
       can't be finalized because superclass STATE
       is not defined yet

Solution

  • From the documentation for defclass it is clear that you are creating missionary-state by extending the parent class state.

    Now the error message gives an indication that you have tried to make an instance of missionary-state before defining missionary-state's parent class state. It is not a standard class so you need to tell the system what that is.

    If you didn't intend it so be a sub class of state you just remove the parent class in the definition:

    (defclass missionary-state ()
      ...)
    

    Now it's a direct sub class of standard-object and standard-class.