1

Can I get in LISP all the method names from a class?

Actually I need the methods, which have

set-

in their names.

3
  • What you are looking for is called MOP - MetaObject Protocol. Commented Dec 6, 2016 at 20:41
  • 1
    Methods are not defined on classes. They specialize generic function according to one or more arguments. You may want to find all methods named "set-" which specializes on the class as the first argument. But perhaps more importantly, why? Commented Dec 6, 2016 at 20:55
  • 1
    @coredump using SET I am setting some properties and I need to print those properties names. Some of them are saved in slots, but there are properties which are not saved in slots, so getting all the slots is not enough. Commented Dec 6, 2016 at 21:17

1 Answer 1

3

For LispWorks:

(defun find-all-methods (class prefix)
  (loop for method in (clos:specializer-direct-methods class)
        for gf           = (method-generic-function method)
        for fname        = (generic-function-name gf)
        for fname-string = (when (symbolp fname) (symbol-name fname))
        when (and (stringp fname-string)
                  (>= (length fname-string)
                      (length prefix))
                  (string= fname-string prefix
                           :end1 (length prefix)
                           :end2 (length prefix)))
        collect method))

Example:

CL-USER 20 > (pprint (find-all-methods (find-class 'capi:button) "PRINT-"))

(#<STANDARD-METHOD CAPI:PRINT-COLLECTION-ITEM NIL (CAPI:BUTTON T) 40E06173D3>
 #<STANDARD-METHOD CAPI:PRINT-CAPI-BUTTON NIL (CAPI:BUTTON) 40E05F9DDB>)
Sign up to request clarification or add additional context in comments.

1 Comment

This also works on SBCL using (ql:quickload 'closer-mop) and adjusting the missing functions to the ones from the closer-mop package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.