Find all of the methods specializing a given type
Asked Answered
M

1

6

Is there a way to find all of the functions that specialize on a given type?

I envision something you could execute from the repl like (find-all-specializing-methods 'my-class) and it would return a list of methods like (mypackage1:my-method-1 my-package2:my-method-2 etc.)

I think there must be an easy way to do this because the MOP itself probably needs to store such a list to decide which methods to call.

Mahratta answered 11/1, 2013 at 10:10 Comment(2)
The MOP does not really need that. CLOS uses COMPUTE-APPLICABLE-METHODS.Ari
@wvxvw thank you, that is close enough for my purposes, please post as an answer and I will accept itMahratta
C
5

In order to find that you could look into slime-who-specializes and find out how to do it for your setup.

Following the definitions, I got so far as here (for SBCL):

#+#.(swank-backend::sbcl-with-xref-p)
(progn
  (defmacro defxref (name &optional fn-name)
    `(defimplementation ,name (what)
       (sanitize-xrefs   
        (mapcar #'source-location-for-xref-data
                (,(find-symbol (symbol-name (if fn-name
                                                fn-name
                                                name))
                               "SB-INTROSPECT")
                  what)))))
  (defxref who-calls)
  (defxref who-binds)
  (defxref who-sets)
  (defxref who-references)
  (defxref who-macroexpands)
  #+#.(swank-backend:with-symbol 'who-specializes-directly 'sb-introspect)
  (defxref who-specializes who-specializes-directly))

This functionality is implemented separately for different Lisps, so if you need particular details, you would need to look into: swank-<your lisp>.lisp file and search for implementation of who-specializes generic function.

Contribution answered 11/1, 2013 at 14:27 Comment(1)
Any chance someone could break this down a bit more? I got an error trying to plug this into my slime toplevel: The function SWANK/BACKEND::SBCL-WITH-XREF-P is undefined. Even had I not gotten that error, I'd like to better understand the relevant pieces.Microminiaturization

© 2022 - 2024 — McMap. All rights reserved.