LispWorks 8: c2mop:compute-applicable-methods-using-classes's default method specializes wrong class
g000001 opened this issue · 4 comments
On lispworks8, c2mop:compute-applicable-methods-using-classes
specializes on c2mop:standard-generic-function
.
On other platform like SBCL, it specializes on cl:generic-function
.
(mapcar (lambda (m)
(mapcar #'class-name (c2mop:method-specializers m)))
(c2mop:generic-function-methods #'c2mop:compute-applicable-methods-using-classes))
on lispworks8
→ ((c2mop:standard-generic-function t))
on sbcl
→ ((cl:generic-function t))
IMHO (c2mop:compute-applicable-methods-using-classes cl:generic-function) is more natural and portable like other platforms.
According to the CLOS MOP specification, the primary method for compute-applicable-methods-using-class is specialized on standard-generic-function, not generic-function. See https://franz.com/support/documentation/10.1/doc/mop/dictionary.html#compute-applicable-methods-using-classes
How about defaulting to cl:standard-generic-function
rather than c2mop:standard-generic-function
?
Defaulting to c2mop:standard-generic-function
is bit annoying because,
it causes unsynmetric behavior between compute-applicable-methods
and compute-applicable-methods-using-classes
(on LispWorks 8)
(c2mop:defclass C () ())
(c2mop:defmethod M ((I C)))
(c2cl:compute-applicable-methods #'M (list (c2cl:class-prototype (find-class 'C))))
→ (#<standard-method m nil (c) 801025DE43>)
(c2cl:compute-applicable-methods-using-classes #'M (list (find-class 'C)))
>>>error: No applicable methods for #<lisp:standard-generic-function compute-applicable-methods-using-classes 826081B6E9> with args
IMHO most of c2mop:defgeneric
or c2mop:defmethod
usage is without explicit (:generic-function-class c2mop:standard-generic-function)
option.
and c2mop:defgeneric
sets implicit default to cl:standard-generic-function
rather than c2mop's GF.
The CLOS MOP imposes a number of restrictions what portable programs can and cannot do. Adding methods to predefined metaobject classes is generally not a good idea. It might work in this particular case, but it might not work in others, and it's better to be consistent.
The defaults for defclass and defgeneric are chosen so that if you don't choose and explicit :metaclass or :generic-function-class, you get something that primarily performs well, which means falling back to the built-in metaobject classes. The CLOS MOP is primarily designed for defining your own metaobject classes, and then you have to use :metaclass and :generic-function-class anyway.
You can also :use :closer-common-lisp, and then CLOS-related symbols are taken from c2mop instead of cl.
I know that invoking compute-applicable-method-using-classes is inconvenient if you don't have your own metaobject classes defined, but that's actually not its main purpose anyway. The main purpose is to change how applicable methods are determined for your own generic function metaobject class.
Can't you just use compute-applicable-methods? What's your use case?
Thank you for your explaining design choices about closer-mop.
I will just use compute-applicable-methods
.
Much appreciated.