Package compatible-metaclasses
Description
All symbols from this package should normally be explicitly qualified, such as compatible-metaclasses:standard-class
.
Don't (:use)
!
compatible-metaclasses
validates superclasses according to a simple substitution model,
thereby greatly simplifying the definition of class mixins.
Traditionally, defining "class mixins" (subclasses of metaclasses, for instance if you just want to add a slot and/or a few methods) has been surprisingly hard due to the combinatorial explosion of c2mop:validate-superclass methods needed when using the naive approach. This library defines a simple substitution model that completely solves this problem.
Here is an example usage:
(defclass my-class-mixin (compatible-metaclasses:standard-class
metaclass)
()
(:metaclass compatible-metaclasses:standard-metaclass
)
(:validate-as metaclass))
Note that compatible-metaclasses:standard-metaclass
, being used as the metaclass of a metaclass, is thus a metametaclass!
Also note that compatible-metaclasses:standard-class
will be effectively ignored in any subclasses of my-class-mixin
that don't have compatible-metaclasses:standard-metaclass
as their metaclass, which is exactly what we want since we can't safely make any assumptions about how c2mop:validate-superclass should behave (i.e. metaclass compatibility) for those subclasses.
All symbols from this package should normally be explicitly qualified, such as compatible-metaclasses:standard-class
.
Don't (:use)
!
Metaclasses inheriting from this class will potentially substitute the class and/or the superclass for another class during c2mop:validate-superclass.
(class compatible-metaclasses:class
) (superclass class) => compatiblep
Call c2mop:validate-superclass on the compatible-metaclasses:substitute
for class and superclass, unless the substitute is the original class, in which case, call the next method.
(class class) (superclass compatible-metaclasses:class
) => compatiblep
Call c2mop:validate-superclass on class and the compatible-metaclasses:substitute
for superclass, unless the substitute is the original superclass, in which case, call the next method.
class => substitute
Returns the substitute to use instead of the original class for purposes of superclass validation by c2mop:validate-superclass. Returns class if no substitution is desired.
(class compatible-metaclasses:standard-class
) => substitute
Returns (or (
.compatible-metaclasses:metasubstitute
(class-of class)) class)
See the corresponding method.
compatible-metaclasses:validate-as-mixin
, compatible-metaclasses:metasubstitute-mixin
, standard-class
Use this metametaclass as the metaclass of your metaclass to designate the metaclass to use instead of your metaclass for purposes of validation.
(class compatible-metaclasses:standard-metaclass
) (superclass class) => compatiblep
Call c2mop:validate-superclass on the class standard-object and superclass.
(class class) (superclass compatible-metaclasses:standard-metaclass
) => compatiblep
Call c2mop:validate-superclass on class and the class standard-object.
Slots:
((validate-as :initarg :validate-as
:reader compatible-metaclasses:validate-as
:type class
:initform (find-class 'standard-class)
:documentation "The metaclass to use for purposes of validation."))
(class compatible-metaclasses:validate-as-mixin
) &key validate-as => canonicalized-options
If validate-as was supplied, then canonicalize it as follows:
First, if validate-as is a list of one element, then let validate-as be that element. This is done to support defclass class option syntax.
Then, call enhanced-find-class:find-class on validate-as.
metametaclass => metaclass
Returns the metaclass to use instead of the instance of this metametaclass to check compatibility using c2mop:validate-superclass.
Slots:
((metasubstitute :initarg :metasubstitute
:reader compatible-metaclasses:metasubstitute
:type class))
(mixin compatible-metaclasses:metasubstitute-mixin
) &key
Sets the value of the metasubstitute slot to (c2mop:class-prototype (c2mop:ensure-finalized (
.compatible-metaclasses:validate-as
mixin)))
(mixin compatible-metaclasses:metasubstitute-mixin
) &key
Same as above.
metametaclass => metasubstitute
nil
.Returns the substitute that instances of this metametaclass which inherit from compatible-metaclasses:standard-class
should use to check compatibility using c2mop:validate-superclass, or nil
if the original class should be used.
(metametaclass compatible-metaclasses:metasubstitute-mixin
) => metasubstitute
Returns the value of the metasubstitute slot.
(metametaclass class) => metasubstitute
Returns nil
.