eieio.el: another constructor question

Jan Moringen <[email protected]> Mon, 16 Nov 2009 03:04:42 +0100
Newsgroups gmane.emacs.eieio
Message-ID <3981_1258337084_ZZg0K323Nmdz7.00_1258337082.6481.45.camel@localhost.localdomain>
--Boundary_(ID_15zFZkqXmM1J2EqEKFI5WA)
Content-type: text/plain; charset=UTF-8
Content-transfer-encoding: 7BIT

Hi,

while working with a class hierarchy similar to this

 a
/ \
b c
\ /
 d

I discovered surprising (to me) behavior. Each class has an
initialize-instance method and they run in one of the expected orders:
d, b, c, a.

The surprising part: each initialize-instance method uses
call-next-method. The methods of d and b provide replacement arguments
and extent the list of initargs with :c 'c and :d 'd respectively.
However, when c uses (call-next-method) the eieio-generic-call-arglst of
the original call (to initialize-instance of d) is used. I expected the
replacement arguments provided in the initialize-instance methods of d
and b to be propagated to the call of c's initialize-instance.

With instrumented methods that print their arguments, the following
happens:

(d "" :a 'a)
| d (:a a)
| b (:a a :d d)
| c (:a a :d d :b b)
| a (:a a)           ; (call-next-method) in c calls a's 
                     ; initialize-instance with original argument list

I expected the result to be more like this:

(d "" :a 'a)
| d (:a a)
| b (:a a :d d)
| c (:a a :d d :b b)
| a (:a a :d d :b b) ; initialize-instance of a is called with modified 
                     ; argument list

I produced the second trace by changing the following in eieio.el
(call-next-method):

@@ -2174,6 +2222,8 @@
 	(apply 'no-next-method (car newargs) (cdr newargs))
       (let* ((eieio-generic-call-next-method-list
 	      (cdr eieio-generic-call-next-method-list))
+	     (eieio-generic-call-arglst
+	      newargs)
 	     (scoped-class (cdr next))
 	     (fcn (car next))
 	     )

Is this an improvement?

Kind regards,
Jan

--Boundary_(ID_15zFZkqXmM1J2EqEKFI5WA)
Content-type: text/x-emacs-lisp; name=bla.el; charset=UTF-8
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=bla.el

(defclass a ()
  ((a :initarg :a)
   (b :initarg :b)
   (c :initarg :c)
   (d :initarg :d)))

(defmethod initialize-instance ((this a) slots)
  (message "a %s" slots)
  (when (next-method-p)
    (call-next-method)))

(defclass b (a)
  ())

(defmethod initialize-instance ((this b) slots)
  (message "b %s" slots)
  (when (next-method-p)
    (call-next-method
     this (append slots (list :b 'b)))))

(defclass c (a)
  ())

(defmethod initialize-instance ((this c) slots)
  (message "c %s" slots)
  (when (next-method-p)
    (call-next-method)))

(defclass d (b c)
  ())

(defmethod initialize-instance ((this d) slots)
  (message "d %s" slots)
  (when (next-method-p)
    (call-next-method
     this (append slots (list :d 'd)))))

(d "" :a 'a)

--Boundary_(ID_15zFZkqXmM1J2EqEKFI5WA)
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
--Boundary_(ID_15zFZkqXmM1J2EqEKFI5WA)
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
cedet-eieio mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cedet-eieio

--Boundary_(ID_15zFZkqXmM1J2EqEKFI5WA)--