unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mikael Djurfeldt <mikael@djurfeldt.com>
To: Maxime Devos <maximedevos@telenet.be>
Cc: "janneke@gnu.org" <janneke@gnu.org>,
	guile-devel <guile-devel@gnu.org>,
	"Ludovic Courtès" <ludo@gnu.org>, guile-user <guile-user@gnu.org>,
	"Andy Wingo" <wingo@pobox.com>
Subject: Re: Keywords in GOOPS methods
Date: Sat, 23 Nov 2024 16:41:32 +0100	[thread overview]
Message-ID: <CAA2XvwLyuPc8X=QMaAFthYkusJEFyQLAcz46HkPPSx9DJ=9Evg@mail.gmail.com> (raw)
In-Reply-To: <20241123163143.gFXi2D00541pia201FXiCK@xavier.telenet-ops.be>

[-- Attachment #1: Type: text/plain, Size: 2668 bytes --]

Hi Maxime,

Well, these particular examples aren't valid since GOOPS doesn't allow type
specifiers for keyword arguments. (It's the same in CLOS.) Type dispatch is
done *only* on the required arguments.

Best regards,
Mikael

On Sat, Nov 23, 2024 at 4:31 PM Maxime Devos <maximedevos@telenet.be> wrote:

> >Any opinions on what is best: Having a define-method* or having the
> functionality in define-method itself?
>
>
>
> You can’t unify define-method with define-method* without making some
> arbitrary choices in some special cases (the same applies to define-method*
> too actually, and also to define-method on its own without keyword
> arguments, but it needs to be considered and documented somewhere).
>
>
>
> Consider (please ignore syntax errors, don’t have much practice with
> GOOPS):
>
>
>
> (define-method (f (a <keyword>) (b <integer>))
>   (pk 'positional a b))
>
>
>
> ;; what I mean is to only consider ‘foo’ that are of class <number>,  I
> don’t mean <number> as default value
>
> (define-method (f (#:key foo <number>))
>   (pk 'keyword foo))
>
>
>
> An ambiguous case: (f #:foo 1). This matches both the first and second
> implementation. <integer> is more specific that <number>, so this sounds
> like the first method should win. But, ‘#:foo’ is more specific than
> <keyword>, so the second should win.
>
>
>
> I don’t know what the rule is for positional arguments (I assume earlier
> arguments are more important in case of ambiguity?). However, the same rule
> cannot be applied to keyword arguments, since they aren’t positional.
> Consider:
>
>
>
> (define-method (g (#:key foo <integer>) (#:key bar <object>))
>
>   (pk 'integer foo))
>
>
>
> (define-method (g (#:key bar <symbol>) (#:key foo <object>))
>
>   (pk 'symbol bar))
>
>
>
> (g #:foo 1 #:bar a) ;integer or symbol?
>
> (g #:bar a #:foo 1) ;does this produce the same result?
>
>
>
> Either ‘integer’ or ‘symbol’ would be appropriate, but it shouldn’t depend
> on whether #:foo or #:bar is written first in the argument call. Now #:foo
> and #:bar need to be (ideally deterministically) ordered, but any
> particular ordering is somewhat arbitrary, and it’s a bit against the
> notion of keyword arguments – orderings are more a thing for _*positional*_
> arguments.
>
>
>
> Potential escape: in case of ambiguity, give up and throw some kind of
> exception. Not ideal, but at least it’s not random, doesn’t depend on how
> the keyword arguments were worded, and it would be limited to keyword
> methods.
>
>
>
> Best regards,
>
> Maime Devos
>

[-- Attachment #2: Type: text/html, Size: 5052 bytes --]

  reply	other threads:[~2024-11-23 15:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-19 16:41 Keywords in GOOPS methods Mikael Djurfeldt
2024-11-21 20:33 ` Mikael Djurfeldt
2024-11-21 20:33   ` Mikael Djurfeldt
2024-11-21 22:00   ` janneke
2024-11-21 22:51     ` Mikael Djurfeldt
2024-11-22 11:46       ` Tomas Volf
2024-11-22 12:28         ` Mikael Djurfeldt
2024-11-22 12:20       ` janneke
2024-11-22 12:29         ` Mikael Djurfeldt
2024-11-22 23:04           ` Mikael Djurfeldt
2024-11-25 23:51         ` Keywords in define-method Mikael Djurfeldt
2024-11-26  0:13           ` Mikael Djurfeldt
2024-11-26  9:33             ` Mikael Djurfeldt
2024-11-26 18:40               ` Mikael Djurfeldt
2024-11-23 15:31       ` Keywords in GOOPS methods Maxime Devos via General Guile related discussions
2024-11-23 15:41         ` Mikael Djurfeldt [this message]
2024-11-23 15:49           ` Maxime Devos via General Guile related discussions
2024-11-24 11:56             ` Mikael Djurfeldt

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='CAA2XvwLyuPc8X=QMaAFthYkusJEFyQLAcz46HkPPSx9DJ=9Evg@mail.gmail.com' \
    --to=mikael@djurfeldt.com \
    --cc=guile-devel@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=janneke@gnu.org \
    --cc=ludo@gnu.org \
    --cc=maximedevos@telenet.be \
    --cc=wingo@pobox.com \
    /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).