(rontolisp) docs
← Special Forms

defclass

(defclass name (superclass?) ((slot slot-option...) ...) class-option...)

Defines a class and returns the name symbol. This is a static CLOS subset: at most one superclass (single inheritance), and instances are plain tagged lists created with make-instance (like defstruct instances, they satisfy consp and print as their list representation). Slot options:

  • :initarg keyword — the constructor keyword for the slot (defaults to the slot-name keyword)
  • :initform expr — the default value, evaluated at construction time when the slot is not supplied (defaults to nil; there is no unbound-slot state)
  • :reader fn — defines fn as a reader function
  • :accessor fn — like :reader, and additionally a setf-able place

A subclass inherits every slot of its superclass (redefining an inherited slot is an error) and its instances match the superclass's defmethod class specializers. Reader/accessor functions are ordinary defuns, so they are first-class. The class option (:documentation "...") is accepted and ignored; other class options, other slot options (:allocation, :writer, :type, ...), and multiple inheritance are errors. On the compilation path defclass is only supported as a top-level form; there are no runtime class operations (find-class, change-class, class redefinition).