Classes and instances
This is the syntax for defining a new class. It defines modern-fourth-grader, built on fourth-grader, with an additional slot, computer, and a new default value for teacher.
? (defclass modern-fourth-grader
(fourth-grader)
((computer :initarg :computer
:initform "Macintosh")
(teacher :initform "We use HyperCard stacks.")))
#<STANDARD-CLASS MODERN-FOURTH-GRADER>
? (setf mariah (make-instance 'modern-fourth-grader))
#<MODERN-FOURTH-GRADER #x51A209>
? (slot-value mariah 'teacher)
"We use HyperCard stacks."
? (slot-value mariah 'computer)
"Macintosh"
? (setf (slot-value mariah 'teacher)
"We program our own in Macintosh Common Lisp.")
"We program our own in Macintosh Common Lisp."
The instance mariah inherits slots and values it does not redefine.
? (slot-value mariah 'school)
"Lawrence School"
Generated with Harlequin WebMaker