From: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: contrib: goops doc: calling next-method
Date: Sat, 11 Mar 2006 12:16:52 +0000 [thread overview]
Message-ID: <87y7zhrxaj.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <IVS45K$D043D44BD3A9439A965DEECC22BC5EC1@poste.it> (Marco Maggi's message of "Tue, 7 Mar 2006 23:36:56 +0100")
"Marco Maggi" <marco.maggi-ipsu@poste.it> writes:
> Ciao,
>
> I propose the following to be appended to the
> Next-method node in the GOOPS tutorial Texinfo.
Thanks. I think I understand your concerns, but the text you have
proposed seems a little long-winded and insufficiently explicit about
the background of your concerns.
What do you think about the following revision of the Next-method
node? Does it cover everything that you wanted to cover?
Neil
@node Next-method, Example, Generic functions and methods, Generic functions
@subsection 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 @code{next-method}.
@lisp
(define-method (Test (a <integer>)) (cons 'integer (next-method)))
(define-method (Test (a <number>)) (cons 'number (next-method)))
(define-method (Test a) (list 'top))
@end lisp
With these definitions,
@lisp
(Test 1) @result{} (integer number top)
(Test 1.0) @result{} (number top)
(Test #t) @result{} (top)
@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.)
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
next prev parent reply other threads:[~2006-03-11 12:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-07 22:36 contrib: goops doc: calling next-method Marco Maggi
2006-03-11 12:16 ` Neil Jerram [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-03-12 6:09 Marco Maggi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y7zhrxaj.fsf@ossau.uklinux.net \
--to=neil@ossau.uklinux.net \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).