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: Sun, 24 Nov 2024 12:56:55 +0100	[thread overview]
Message-ID: <CAA2XvwJ9Os9yjgCktgKAZCdR5a--T6J7LpJaSo6R2o6Sw1zgXw@mail.gmail.com> (raw)
In-Reply-To: <20241123164914.gFpC2D00841pia206FpC0X@albert.telenet-ops.be>

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

(It's (define-method (f #:key foo) ...).)

This is a valid point. Certainly there should be unambiguous rules so that
we know which method should be selected. (I planned to examine this aspect
before applying my patch to Guile. I was just eager to share what I had
done in order to collect opinions before putting too much effort into it.)

In this case, I would say that positional *should* win since it is most
specific with regards to the specifiers.

The patch I posted actually doesn't result in this, but it could be easily
fixed with a change based on the following consideration:

The motivation for having what you call the "major limitation" of not doing
type dispatch on keyword arguments in GOOPS or CLOS is to strike a
reasonable balance with regards to the complexity of implementation (and
cognitive load for the user, I guess :). In the future, if we come up with
a conceptually simple picture of how to regard method precedence in the
light of typed keyword arguments and also see that this doesn't make the
implementation overly complicated, we can consider extending the
functionality in this direction.

CLOS has a fixed number of required arguments per generic function.  So, in
CLOS it isn't possible to come up with two allowed methods where the order
of dispatch is unclear.

We loosed that up in GOOPS and allow varying number of arguments (which is
a Good Thing). So, you are right that we need to come up with rules that
make the order of dispatch clear.

I propose that the simplest rule which corresponds to restricting type
dispatch to non-keyword arguments is to define the specializer list of
every method with keyword formals like this:

Method formals: ((<F1> <TYPE1>) ... <KEYWORD> ...)

results in

Specializer list: (<TYPE1> ... . <top>)

So

  (method ((x <integer>) . y) ...)

will have the same specializers as

  (method* ((x <integer>) #:key z) ...)

With this definition, positional above will win. In my patch, this
corresponds to changing #''() to #'<top> in the computation of specializers
for keyword methods.

Meanwhile, I've found a further bug in my patch: We need to consider
keyword arguments in re-definition in methods. Fixed now in my still
private code.

Also, I should add that I now lean towards supplying the keyword
functionality in additional syntax method* and define-method*, and keep the
semantics for method and define-method as is.

Best regards,
Mikael

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

> >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.
>
>
>
> That’s a shame, it should support them IMO, it’s a major limitation if it
> doesn’t.
>
>
>
> A variant with untyped keyword arguments:
>
>
>
> (define-method (f (a <keyword>) (b <symbol>))
>
>   (pk 'positional))
>
>
>
> (define-method (f (#:key foo))
>
>   (pk 'optional-keyword foo))
>
>
>
> (f #:foo 'bar)
>
>
>
> Who should win? Both are a quite specific match.
>
>
>
> Best regards,
>
> Maxime Devos
>

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

      reply	other threads:[~2024-11-24 11:56 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
2024-11-23 15:49           ` Maxime Devos via General Guile related discussions
2024-11-24 11:56             ` Mikael Djurfeldt [this message]

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=CAA2XvwJ9Os9yjgCktgKAZCdR5a--T6J7LpJaSo6R2o6Sw1zgXw@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).