[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GOOPS with variable number of arguments
From: |
David Kastrup |
Subject: |
Re: GOOPS with variable number of arguments |
Date: |
Sat, 28 Nov 2015 00:30:12 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Jan Wedekind <address@hidden> 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 <string>) (b <string>)) (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 <string>) (b <string>)) (string-append a b))
> (test "a" "b" "c")
> ; "abc"
>
> Please let me know if there is a solution.
(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 <string>) (b <string>)) (string-append a b))
(display (test "a" "b" "c" "d" "e"))
--
David Kastrup