From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.lisp.guile.user Subject: Re: GOOPS with variable number of arguments Date: Sat, 28 Nov 2015 00:30:12 +0100 Organization: Organization?!? Message-ID: <87r3jbxbp7.fsf@fencepost.gnu.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1448667051 32670 80.91.229.3 (27 Nov 2015 23:30:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 27 Nov 2015 23:30:51 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Nov 28 00:30:42 2015 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a2STR-00089s-Fy for guile-user@m.gmane.org; Sat, 28 Nov 2015 00:30:41 +0100 Original-Received: from localhost ([::1]:58916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2STU-0001FD-E2 for guile-user@m.gmane.org; Fri, 27 Nov 2015 18:30:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2STF-0001AO-Vg for guile-user@gnu.org; Fri, 27 Nov 2015 18:30:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2STB-0008VY-Qu for guile-user@gnu.org; Fri, 27 Nov 2015 18:30:29 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:38399) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2STB-0008VR-JO for guile-user@gnu.org; Fri, 27 Nov 2015 18:30:25 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1a2ST5-0007L6-Bu for guile-user@gnu.org; Sat, 28 Nov 2015 00:30:19 +0100 Original-Received: from x2f49f86.dyn.telefonica.de ([2.244.159.134]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 28 Nov 2015 00:30:19 +0100 Original-Received: from dak by x2f49f86.dyn.telefonica.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 28 Nov 2015 00:30:19 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 51 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: x2f49f86.dyn.telefonica.de X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) Cancel-Lock: sha1:LEUTba5WIw84A6K2cj62X9lMcqk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:12202 Archived-At: --=-=-= Content-Type: text/plain Jan Wedekind writes: > Hi, > I am trying to implement n-ary operations for different types of objects. > When specialising "+" for two arguments, it will automatically work on > more arguments. > > (use-modules (oop goops) (srfi srfi-1)) > (define-generic +) > (define-method (+ (a ) (b )) (string-append a b)) > (+ "a" "b" "c") > ; "abc" > > However I have trouble figuring out a method definition for test which > would result in the same behaviour. > > (define (test . args) ...) > (define-generic test) > (define-method (test (a ) (b )) (string-append a b)) > (test "a" "b" "c") > ; "abc" > > Please let me know if there is a solution. --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=bab.scm (use-modules (oop goops)) (define-generic test) (define-method (test a b c . rest) (if (null? rest) (test (test a b) c) (apply test (test (test a b) c) rest))) (define-method (test (a ) (b )) (string-append a b)) (display (test "a" "b" "c" "d" "e")) --=-=-= Content-Type: text/plain -- David Kastrup --=-=-=--