From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: contrib: goops doc: calling next-method Date: Sat, 11 Mar 2006 12:16:52 +0000 Message-ID: <87y7zhrxaj.fsf@ossau.uklinux.net> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1142079663 14834 80.91.229.2 (11 Mar 2006 12:21:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 11 Mar 2006 12:21:03 +0000 (UTC) Cc: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Mar 11 13:21:00 2006 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FI35d-0001NM-EP for guile-user@m.gmane.org; Sat, 11 Mar 2006 13:20:59 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FI35c-000705-H8 for guile-user@m.gmane.org; Sat, 11 Mar 2006 07:20:56 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FI35W-000700-9S for guile-user@gnu.org; Sat, 11 Mar 2006 07:20:50 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FI35U-0006zo-9G for guile-user@gnu.org; Sat, 11 Mar 2006 07:20:49 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FI35U-0006zl-4R for guile-user@gnu.org; Sat, 11 Mar 2006 07:20:48 -0500 Original-Received: from [80.84.72.33] (helo=mail3.uklinux.net) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FI38z-0005c2-SL for guile-user@gnu.org; Sat, 11 Mar 2006 07:24:26 -0500 Original-Received: from laruns (host86-129-144-246.range86-129.btcentralplus.com [86.129.144.246]) by mail3.uklinux.net (Postfix) with ESMTP id 170A2409FB9; Sat, 11 Mar 2006 12:20:47 +0000 (UTC) Original-Received: from laruns (laruns [127.0.0.1]) by laruns (Postfix) with ESMTP id EFA7C6F7B4; Sat, 11 Mar 2006 12:16:52 +0000 (GMT) Original-To: "Marco Maggi" In-Reply-To: (Marco Maggi's message of "Tue, 7 Mar 2006 23:36:56 +0100") User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:5219 Archived-At: "Marco Maggi" 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 )) (cons 'integer (next-method))) (define-method (Test (a )) (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 ) 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