unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Catching no generic method in EIEIO
@ 2016-05-25 16:03 Phillip Lord
  2016-05-25 16:06 ` Dmitry Gutov
  2016-05-25 18:19 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Phillip Lord @ 2016-05-25 16:03 UTC (permalink / raw)
  To: help-gnu-emacs



Using EIEIO I can define a `slot-missing' method to catch "No Such Slot"
errors for objects which do not have this slot.

I've looked but as far as I can see, there is no ability to catch a
missing implementation for a method.

So:

(defclass One()())

(defclass Two()())

(defmethod met((o One))
  'hello)

(met (One))
(met (Two))

The last form crashes -- I could, of course, implement this using
defmethod on Two, but I want to this for any method.

Phil



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Catching no generic method in EIEIO
  2016-05-25 16:03 Catching no generic method in EIEIO Phillip Lord
@ 2016-05-25 16:06 ` Dmitry Gutov
  2016-05-25 18:19 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry Gutov @ 2016-05-25 16:06 UTC (permalink / raw)
  To: Phillip Lord, help-gnu-emacs

On 05/25/2016 07:03 PM, Phillip Lord wrote:

> I've looked but as far as I can see, there is no ability to catch a
> missing implementation for a method.

Why not use defgeneric, and provide a default implementation for the method?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Catching no generic method in EIEIO
  2016-05-25 16:03 Catching no generic method in EIEIO Phillip Lord
  2016-05-25 16:06 ` Dmitry Gutov
@ 2016-05-25 18:19 ` Stefan Monnier
  2016-05-26 15:07   ` Phillip Lord
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2016-05-25 18:19 UTC (permalink / raw)
  To: help-gnu-emacs

> The last form crashes -- I could, of course, implement this using
> defmethod on Two, but I want to this for any method.

    (defmethod ((o t))
      ...)

should do the trick.


        Stefan


PS: Of course, I also recommend you switch to cl-generic
(i.e. use (cl-defmethod ...)).  It's more featureful and much faster.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Catching no generic method in EIEIO
  2016-05-25 18:19 ` Stefan Monnier
@ 2016-05-26 15:07   ` Phillip Lord
  2016-05-28 18:29     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Phillip Lord @ 2016-05-26 15:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> The last form crashes -- I could, of course, implement this using
>> defmethod on Two, but I want to this for any method.
>
>     (defmethod ((o t))
>       ...)
>
> should do the trick.

Didn't know you could do that, but it's not what I wanted. It implements
the method for all objects. Where was what I wanted was to implement all
methods on one object (or class).

Not that it matters now, as I have realised I was doing the wrong thing
anyway, that inheritance will do what I need.

> PS: Of course, I also recommend you switch to cl-generic
> (i.e. use (cl-defmethod ...)).  It's more featureful and much faster.

I'm going to fix all that when I port everything to emacs-25. I'm just
waiting till that hits the shelf.

Phil



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Catching no generic method in EIEIO
  2016-05-26 15:07   ` Phillip Lord
@ 2016-05-28 18:29     ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2016-05-28 18:29 UTC (permalink / raw)
  To: help-gnu-emacs

>>> The last form crashes -- I could, of course, implement this using
>>> defmethod on Two, but I want to this for any method.
>> (defmethod ((o t))
>> ...)
>> should do the trick.
> Didn't know you could do that, but it's not what I wanted. It implements
> the method for all objects. Where was what I wanted was to implement all
> methods on one object (or class).

FWIW, I think you can might be able to do that (at least for those
methods which don't have a default case like the one I provided above)
with something like

    (cl-defmethod cl-no-applicable-method (generic (x <myclass>) &rest args)
aka
    (defmethod no-applicable-method ((x <myclass>) generic &rest args)

but this will only catch those methods where the dispatch on <myclass>
was done on the first argument.

>> PS: Of course, I also recommend you switch to cl-generic
>> (i.e. use (cl-defmethod ...)).  It's more featureful and much faster.
> I'm going to fix all that when I port everything to emacs-25. I'm just
> waiting till that hits the shelf.

There's a forward compatibility cl-generic package in GNU ELPA, so you
should be able to start using it without dropping
backward compatibility.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-05-28 18:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-25 16:03 Catching no generic method in EIEIO Phillip Lord
2016-05-25 16:06 ` Dmitry Gutov
2016-05-25 18:19 ` Stefan Monnier
2016-05-26 15:07   ` Phillip Lord
2016-05-28 18:29     ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).