* GOOPS with variable number of arguments
@ 2015-11-27 22:58 Jan Wedekind
2015-11-27 23:30 ` David Kastrup
0 siblings, 1 reply; 3+ messages in thread
From: Jan Wedekind @ 2015-11-27 22:58 UTC (permalink / raw)
To: guile-user
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GOOPS with variable number of arguments
2015-11-27 22:58 GOOPS with variable number of arguments Jan Wedekind
@ 2015-11-27 23:30 ` David Kastrup
2015-11-28 22:24 ` Jan Wedekind
0 siblings, 1 reply; 3+ messages in thread
From: David Kastrup @ 2015-11-27 23:30 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 732 bytes --]
Jan Wedekind <jan@wedesoft.de> 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.
[-- Attachment #2: bab.scm --]
[-- Type: text/plain, Size: 276 bytes --]
(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"))
[-- Attachment #3: Type: text/plain, Size: 20 bytes --]
--
David Kastrup
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: GOOPS with variable number of arguments
2015-11-27 23:30 ` David Kastrup
@ 2015-11-28 22:24 ` Jan Wedekind
0 siblings, 0 replies; 3+ messages in thread
From: Jan Wedekind @ 2015-11-28 22:24 UTC (permalink / raw)
To: David Kastrup; +Cc: guile-user
Ok, thanks. I'll use that solution.
On Sat, 28 Nov 2015, David Kastrup wrote:
> Jan Wedekind <jan@wedesoft.de> 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.
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-11-28 22:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-27 22:58 GOOPS with variable number of arguments Jan Wedekind
2015-11-27 23:30 ` David Kastrup
2015-11-28 22:24 ` Jan Wedekind
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).