Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LispWorks 8: c2mop:compute-applicable-methods-using-classes's default method specializes wrong class #21

Closed
g000001 opened this issue Nov 11, 2022 · 4 comments

Comments

@g000001
Copy link

g000001 commented Nov 11, 2022

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.

@pcostanza
Copy link
Owner

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

@g000001
Copy link
Author

g000001 commented Nov 11, 2022

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.

@pcostanza
Copy link
Owner

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?

@g000001
Copy link
Author

g000001 commented Nov 11, 2022

Thank you for your explaining design choices about closer-mop.
I will just use compute-applicable-methods.
Much appreciated.

@g000001 g000001 closed this as completed Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants