guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: primitive-generics are limited in their arities


From: Mikael Djurfeldt
Subject: Re: primitive-generics are limited in their arities
Date: Mon, 14 Jul 2003 18:03:15 +0200
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux)

Andy Wingo <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]