[Ecls-list] Objective achieved

Juan Jose Garcia-Ripoll jjgarcia at users.sourceforge.net
Wed Feb 13 21:42:17 UTC 2008

Haha, I was too fast at claiming victory. There was a fundamental flaw
in the implementation. Namely, the stack frames have dynamic extent,
but some methods can create closures over the local function
CALL-NEXT-METHOD. An example follows:

> (defmethod foo ((a t)) (print a))
> (defmethod foo ((a integer)) (flet ((closure () (call-next-method))) #'closure))
> (foo 1)
#<bytecompiled-function CLOSURE>
> (funcall *)


Well, it is not exactly "natural", but unfortunately we have to take
care of this possibility. Things are not so bad. We have to enlarge
the list of tests as shown below. Note that the floating point case,
which creates a local function, conses. This is because in this case
the code walker has noticed that CALL-NEXT-METHOD is used in a local
function, which might potentially become a closure, and has to copy
the function arguments into a list. Incidentally, even with this
complication, the CLOS implementation has become simpler (see

I have just committed these changes to the "new_apply" branch. It
seems that ECL still passes all tests, but I will wait a little bit
before merging these changes into the main tree.


;;; This has to be compiled to get the values shown next.

(defmethod foo ((a string)) (call-next-method 1))

(defmethod foo ((a integer)) (call-next-method))

(defmethod foo ((a float)) (flet ((faa () (call-next-method))) (faa)))

(defmethod foo ((a t)) a)

(dotimes (i 100) (foo 1.0) (foo 'a) (foo "A"))

(time (dotimes (i 100000) (foo 'a)))
real time : 0.048 secs
run time  : 0.048 secs
gc count  : 1 times
consed    : 0 bytes

(time (dotimes (i 100000) (foo 1)))
real time : 0.072 secs
run time  : 0.072 secs
gc count  : 1 times
consed    : 488 bytes

(time (dotimes (i 100000) (foo "A")))
real time : 0.081 secs
run time  : 0.078 secs
gc count  : 1 times
consed    : 1600000 bytes

(time (dotimes (i 100000) (foo 0.1)))
real time : 0.092 secs
run time  : 0.091 secs
gc count  : 1 times
consed    : 1600000 bytes

Facultad de Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)

More information about the ecl-devel mailing list