Re: Default methods :before and :after aren't called

Jan Moringen <[email protected]> Thu, 03 Jun 2010 00:24:09 +0200
Newsgroups gmane.emacs.eieio
Message-ID <19226_1275517184_ZZh003p2nu07U.00_1275517449.4894.177.camel@localhost.localdomain>
Hi Frank.

> (defclass bar ()
>   ())
> 
> (func (make-instance 'bar))
> ;; Hmmm what about the :before and :after default methods?
> ;;
> ;; default method :primary: [object bar bar]

This behavior really is inconsistent. The first three versions of your
`func' method get defined as "generic methods" (not sure if such a thing
exists in CLOS) of the generic function `func'. In EIEIO, this generic
definition seems to mean that the method will be used if the first
argument is neither an object nor a class. This would be similar to a
CLOS system:

; SLIME 2010-02-26
CL-USER> (defgeneric bla (a b c))
#<STANDARD-GENERIC-FUNCTION BLA (0)>
CL-USER> (defmethod bla (a b c) 1)
#<STANDARD-METHOD BLA (T T T) {B6225F1}>
CL-USER> (bla 1 2 3)
1

However, looking at the the EIEIO source leaves me wondering, how that
would work.

In your example, this code causes the strange behavior:

;; :after methods
(setq tlambdas
  (if mclass
      (eieiomt-method-list method method-after mclass)
    (list (eieio-generic-form method method-after nil))))
  ;;(or (and mclass (eieio-generic-form method method-after mclass))
  ;;	(eieio-generic-form method method-after nil)))

[...]

;; :primary methods
(setq tlambdas
      (or (and mclass (eieio-generic-form method method-primary mclass))
	  (eieio-generic-form method method-primary nil)))

The commented part would treat :after methods like :primary methods. I
don't know what purpose the change served.

If you only want the generic version to be executed for objects of any
class that does not have specialized methods of the generic function,
you can use:

(defmethod func :before ((this eieio-default-superclass))
  (message "default method :before: %s" this))

(defmethod func :primary ((this eieio-default-superclass))
  (message "default method :primary: %s" this))

(defmethod func :after ((this eieio-default-superclass))
  (message "default method :after: %s" this))

Kind regards,
Jan


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo