[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
contrib: goops doc: calling next-method
From: |
Marco Maggi |
Subject: |
contrib: goops doc: calling next-method |
Date: |
Tue, 7 Mar 2006 23:36:56 +0100 |
Ciao,
I propose the following to be appended to the
Next-method node in the GOOPS tutorial Texinfo.
@noindent
In the following example a class and a superclass define the
same
method:
@example
(use-modules (oop goops))
(define-class <a> ()
one)
(define-class <b> (<a>)
two)
(define-method (alpha (a <a>))
"alpha a")
(define-method (alpha (b <b>))
(list (next-method) "alpha b"))
@end example
@noindent
in the body of the @code{alpha<b>} function it is fine to invoke
@code{next-method} expecting it to invoke @code{alpha<a>}
because both
the @code{alpha} functions take the same number of
arguments. So the
result will be:
@example
(alpha (make <b>))
;; -> ("alpha a" "alpha b")
@end example
With the following definitions: the body of @code{alpha<b>}
invokes the
@code{alpha} function and an infinite loop will result:
@example
(define-method (alpha (b <b>))
(list (alpha b) "alpha b"))
@end example
@noindent
the most specialised @code{alpha} function is
@code{alpha<b>} itself.
With the following definitions:
@example
(use-modules (oop goops))
(define-class <a> ()
one)
(define-class <b> (<a>)
two)
(define-method (alpha (a <a>) c)
(list "alpha a" c))
(define-method (alpha (b <b>))
(list (next-method) "alpha b"))
@end example
@noindent
the code:
@example
(alpha (make <b>))
@end example
@noindent
will raise an error: the invocation of @code{alpha<b>} has
selected the
@code{alpha} functions that take only one parameter; the
invocation of
@code{next-method} in the body of @code{alpha<b>} will not
find any
other less specialised method; we will get an error even
with the
following:
@example
(define-method (alpha (b <b>))
(list (next-method "string") "alpha b"))
@end example
It is possible to invoke @code{alpha<a>} by evaluating the
@code{alpha}
variable directly, with the appropriate number of parameters:
@example
(define-method (alpha (b <b>))
(list (alpha b "string") "alpha b"))
(alpha (make <b>))
;; -> (("alpha a" "string") "alpha b")
@end example
--
Marco Maggi
"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"
- contrib: goops doc: calling next-method,
Marco Maggi <=