* primitive-generics are limited in their arities
@ 2003-07-12 10:25 Andy Wingo
2003-07-14 16:03 ` Mikael Djurfeldt
0 siblings, 1 reply; 3+ messages in thread
From: Andy Wingo @ 2003-07-12 10:25 UTC (permalink / raw)
Hey goops hackers,
I've run into an irritating little bug in primitive-generics where they
are limited to a specific arity. Here's a little example.
guile> (use-modules (oop goops))
guile> (define-method (write (foo <list>) (bar <list>) (baz <list>))
... (display (list foo bar baz))(newline))
guile> (write '(4 5 6) '(6 7) '(5 6))
Backtrace:
In current input:
4: 0* [write (4 5 6) (6 7) (5 6)]
<unnamed port>:4:1: In procedure write in expression (write (quote #)
(quote #) ...):
<unnamed port>:4:1: Wrong number of arguments to #<primitive-generic
write>
ABORT: (wrong-number-of-args)
guile> write
$1 = #<primitive-generic write>
guile> (primitive-generic-generic write)
$2 = #<<generic> write (7)>
guile> ($2 '(4 5 6) '(6 7) '(5 6))
((4 5 6) (6 7) (5 6))
I wonder if this is a problem with the primitive-generic support or if
there's something that I'm doing wrong. It seems unnatural to have to
(define-method write ...)
and then
(set! write (primitive-generic-generic write))
I tried to look into a fix but I got lost. What's the word on this?
Thanks for the help,
wingo.
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: primitive-generics are limited in their arities
2003-07-12 10:25 primitive-generics are limited in their arities Andy Wingo
@ 2003-07-14 16:03 ` Mikael Djurfeldt
2003-07-18 21:45 ` Marius Vollmer
0 siblings, 1 reply; 3+ messages in thread
From: Mikael Djurfeldt @ 2003-07-14 16:03 UTC (permalink / raw)
Cc: djurfeldt
Andy Wingo <wingo@pobox.com> writes:
> Hey goops hackers,
>
> I've run into an irritating little bug in primitive-generics where they
> are limited to a specific arity. Here's a little example.
>
> guile> (use-modules (oop goops))
> guile> (define-method (write (foo <list>) (bar <list>) (baz <list>))
> ... (display (list foo bar baz))(newline))
> guile> (write '(4 5 6) '(6 7) '(5 6))
>
> Backtrace:
> In current input:
> 4: 0* [write (4 5 6) (6 7) (5 6)]
>
> <unnamed port>:4:1: In procedure write in expression (write (quote #)
> (quote #) ...):
> <unnamed port>:4:1: Wrong number of arguments to #<primitive-generic
> write>
> ABORT: (wrong-number-of-args)
> guile> write
> $1 = #<primitive-generic write>
> guile> (primitive-generic-generic write)
> $2 = #<<generic> write (7)>
> guile> ($2 '(4 5 6) '(6 7) '(5 6))
> ((4 5 6) (6 7) (5 6))
>
> I wonder if this is a problem with the primitive-generic support or if
> there's something that I'm doing wrong. It seems unnatural to have to
>
> (define-method write ...)
>
> and then
>
> (set! write (primitive-generic-generic write))
>
> I tried to look into a fix but I got lost. What's the word on this?
The arity of primitive generics is restricted to the arity of their
primitive methods.
Thus, if you want to have a different arity, you need to create a new
generic function. In order to preserve the behavior, you can add the
original functions as the default method:
(define old-write write)
(define write (make <generic> #:name 'write #:default old-write))
(define-method (write (foo <list>) (bar <list>) (baz <list>))
(display (list foo bar baz))
(newline))
M
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: primitive-generics are limited in their arities
2003-07-14 16:03 ` Mikael Djurfeldt
@ 2003-07-18 21:45 ` Marius Vollmer
0 siblings, 0 replies; 3+ messages in thread
From: Marius Vollmer @ 2003-07-18 21:45 UTC (permalink / raw)
Cc: guile-devel
Mikael Djurfeldt <djurfeldt@nada.kth.se> writes:
> The arity of primitive generics is restricted to the arity of their
> primitive methods.
Could this be relaxed, technically? When primitive-generics are
unrestricted in terms of arity, they would be more similar to the
regular generics, which would be nice, I think...
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-07-18 21:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-12 10:25 primitive-generics are limited in their arities Andy Wingo
2003-07-14 16:03 ` Mikael Djurfeldt
2003-07-18 21:45 ` Marius Vollmer
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).