unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mikael Djurfeldt <djurfeldt@nada.kth.se>
Cc: djurfeldt@nada.kth.se
Subject: Re: primitive-generics are limited in their arities
Date: Mon, 14 Jul 2003 18:03:15 +0200	[thread overview]
Message-ID: <xy78yr12j0c.fsf@nada.kth.se> (raw)
In-Reply-To: <20030712102552.GA4329@lark> (Andy Wingo's message of "Sat, 12 Jul 2003 11:25:52 +0100")

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


  reply	other threads:[~2003-07-14 16:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-12 10:25 primitive-generics are limited in their arities Andy Wingo
2003-07-14 16:03 ` Mikael Djurfeldt [this message]
2003-07-18 21:45   ` Marius Vollmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xy78yr12j0c.fsf@nada.kth.se \
    --to=djurfeldt@nada.kth.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).