0

So, I’ve learned enough about generic functions, CLOS, and EIEIO to believe that this should work:

(defclass foo () nil)

(cl-defmethod make-instance ((x foo) &rest args)
  (with-temp-message "Is this thing on?"
    (sit-for 1))
  (cl-call-next-method))

(make-instance 'foo)

But, that just returns a new “foo” object, it doesn’t stop and display a message like I thought it would. Is there something I’m doing wrong here? (Bonus points if there’s a way I can investigate visually what’s going on—eieio-display-method-list doesn’t seem to work anymore, and I’ve tried to look into the internals of how methods are selected but I just get lost in a maze of structs and functions with names like cl--generic-generalizer-specializers-function.)

I’m using Emacs 26.2 on Ubuntu 18.04 LTS.

0

So, the problem works something like this: make-instance is a class-level method, not an instance-level method (after all, when make-instance is run, the object itself hasn’t been created yet), and that means the format for the specializer is different. This actually works:

(defclass foo () nil)

(cl-defmethod make-instance ((cls (subclass foo)) &rest args)
  (with-temp-message "Is this thing on?"
    (sit-for 1))
  (cl-call-next-method))

(make-instance 'foo)

Now, I can’t tell you whether or not arguments are properly passed to the next method or anything like that, but my basic question is now answered so I will mark it as such.

Thanks to Eric Abrahamsen for his help with this!

| improve this answer | |
  • Works without the last nil on Emacs 26.2 for me. – npostavs Apr 24 '19 at 11:06
  • Huh! Thanks for letting me know. I’m on the Git version of Emacs, branch “emacs-26”, pulled and built on April 16, 2019. – Tina Russell Apr 25 '19 at 20:25
  • …Ah, whoops, that /is/ Emacs 26.2. I hadn’t noticed the version bump. Anyway, I just updated and rebuilt Emacs and the example works without the final nil, just like you said. I’ll update the question and answer accordingly. – Tina Russell Apr 26 '19 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.