--- title: Common Lisp Object System --- The Common Lisp Object System is Common Lisp's object-oriented programming system. It was originally implemented as macros over Common Lisp, but merged into the languge as it was standarized. # Benefits According to Peter Norvig, with CLOS "16 of 23 patterns have qualitatively simpler implementation in Lisp or Dylan than in C++"[^norvig]. The circle-ellipse problem, for example, is solved immediately because objects can change class. # Examples ## Simple Example ```lisp (defclass () ((name :reader name ;; Only reader is implemented, so you can't rename a ;; ship :initarg :name :type string) (kind :accessor kind :initarg :kind) (tonnage :accessor tonnage :initarg :tonnage :type float))) (defparameter *my-ship* (make-instance ' :name "USS Walter Mondale" :kind :laundry-ship :tonnage 345)) (class-of *my-ship*) ;; => #> ``` ## Generic Functions # Metaobject Protocol The Metaobject Protocol (MOP) provides mechanisms for extending CLOS by customizing its behaviour on certain classes. Basically, the MOP sees a class as being an instance of a metaclass (Think of it as a kind of 'higher-order' object system, or a 'two tier' object system). # References [^norvig]: [*Design Patterns in Dynamic Programming*][norvig]. [norvig]: http://norvig.com/design-patterns/design-patterns.pdf