[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
8.6.4 Next-method
When you call a generic function, with a particular set of arguments,
GOOPS builds a list of all the methods that are applicable to those
arguments and orders them by how closely the method definitions match
the actual argument types. It then calls the method at the top of this
list. If the selected method’s code wants to call on to the next method
in this list, it can do so by using next-method
.
(define-method (Test (a <integer>)) (cons 'integer (next-method))) (define-method (Test (a <number>)) (cons 'number (next-method))) (define-method (Test a) (list 'top))
With these definitions,
(Test 1) ⇒ (integer number top) (Test 1.0) ⇒ (number top) (Test #t) ⇒ (top)
next-method
is always called as just (next-method)
. The
arguments for the next method call are always implicit, and always the
same as for the original method call.
If you want to call on to a method with the same name but with a
different set of arguments (as you might with overloaded methods in C++,
for example), you do not use next-method
, but instead simply
write the new call as usual:
(define-method (Test (a <number>) min max) (if (and (>= a min) (<= a max)) (display "Number is in range\n")) (Test a)) (Test 2 1 10) -| Number is in range ⇒ (integer number top)
(You should be careful in this case that the Test
calls do not
lead to an infinite recursion, but this consideration is just the same
as in Scheme code in general.)
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on April 20, 2013 using texi2html 5.0.