+;;; Singleton classes.
+
+(defclass singleton-class-mixin (compatible-class)
+ ((instance :initform nil :type (or null standard-object)))
+ (:documentation
+ "A class which has only one instance. All calls to `make-instance' return
+ the same object."))
+
+(defmethod allocate-instance ((class singleton-class-mixin) &key)
+ "If the class already has an instance, return it; otherwise allocate one,
+ store it away, and return that."
+ (with-slots (instance) class
+ (or instance
+ (setf instance (call-next-method)))))
+
+;;;--------------------------------------------------------------------------