mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
(Next-method): Minor improvements to the
text.
This commit is contained in:
parent
32b164aacd
commit
0ea659f3ba
2 changed files with 38 additions and 6 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2008-02-06 Neil Jerram <neil@ossau.uklinux.net>
|
||||||
|
|
||||||
|
* goops-tutorial.texi (Next-method): Minor improvements to the
|
||||||
|
text.
|
||||||
|
|
||||||
2006-09-28 Neil Jerram <neil@ossau.uklinux.net>
|
2006-09-28 Neil Jerram <neil@ossau.uklinux.net>
|
||||||
|
|
||||||
* goops.texi (Slot Options): Added example from Ludovic Courtès
|
* goops.texi (Slot Options): Added example from Ludovic Courtès
|
||||||
|
|
|
@ -690,11 +690,12 @@ In this case,
|
||||||
@node Next-method, Example, Generic functions and methods, Generic functions
|
@node Next-method, Example, Generic functions and methods, Generic functions
|
||||||
@subsection Next-method
|
@subsection Next-method
|
||||||
|
|
||||||
When a generic function is called, the list of applicable methods is
|
When you call a generic function, with a particular set of arguments,
|
||||||
built. As mentioned before, the most specific method of this list is
|
GOOPS builds a list of all the methods that are applicable to those
|
||||||
applied (see@ @ref{Generic functions and methods}). This method may call
|
arguments and orders them by how closely the method definitions match
|
||||||
the next method in the list of applicable methods. This is done by using
|
the actual argument types. It then calls the method at the top of this
|
||||||
the special form @code{next-method}. Consider the following definitions
|
list. If the selected method's code wants to call on to the next method
|
||||||
|
in this list, it can do so by using @code{next-method}.
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
(define-method (Test (a <integer>)) (cons 'integer (next-method)))
|
(define-method (Test (a <integer>)) (cons 'integer (next-method)))
|
||||||
|
@ -702,7 +703,7 @@ the special form @code{next-method}. Consider the following definitions
|
||||||
(define-method (Test a) (list 'top))
|
(define-method (Test a) (list 'top))
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
With those definitions,
|
With these definitions,
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
(Test 1) @result{} (integer number top)
|
(Test 1) @result{} (integer number top)
|
||||||
|
@ -710,6 +711,32 @@ With those definitions,
|
||||||
(Test #t) @result{} (top)
|
(Test #t) @result{} (top)
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
|
@code{next-method} is always called as just @code{(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 @code{next-method}, but instead simply
|
||||||
|
write the new call as usual:
|
||||||
|
|
||||||
|
@lisp
|
||||||
|
(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)
|
||||||
|
@print{}
|
||||||
|
Number is in range
|
||||||
|
@result{}
|
||||||
|
(integer number top)
|
||||||
|
@end lisp
|
||||||
|
|
||||||
|
(You should be careful in this case that the @code{Test} calls do not
|
||||||
|
lead to an infinite recursion, but this consideration is just the same
|
||||||
|
as in Scheme code in general.)
|
||||||
|
|
||||||
@node Example, , Next-method, Generic functions
|
@node Example, , Next-method, Generic functions
|
||||||
@subsection Example
|
@subsection Example
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue