From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mikael Djurfeldt Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: Re: Keywords in GOOPS methods Date: Sat, 23 Nov 2024 16:41:32 +0100 Message-ID: References: <87iksg2qnm.fsf@gnu.org> <20241123163143.gFXi2D00541pia201FXiCK@xavier.telenet-ops.be> Reply-To: mikael@djurfeldt.com Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000015c27206279656ca" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34282"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "janneke@gnu.org" , guile-devel , =?UTF-8?Q?Ludovic_Court=C3=A8s?= , guile-user , Andy Wingo To: Maxime Devos Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Nov 23 16:42:17 2024 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tEsH3-0008dm-Od for guile-devel@m.gmane-mx.org; Sat, 23 Nov 2024 16:42:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tEsGd-0000bd-Ss; Sat, 23 Nov 2024 10:41:51 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tEsGb-0000bG-C6; Sat, 23 Nov 2024 10:41:49 -0500 Original-Received: from mail-ua1-f46.google.com ([209.85.222.46]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tEsGZ-0000T1-Jq; Sat, 23 Nov 2024 10:41:49 -0500 Original-Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-856e4380e34so908029241.2; Sat, 23 Nov 2024 07:41:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732376504; x=1732981304; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lARrvYyR4LF4HtOcnUd+1DVwIgzBn2ou1o0NNgsgEm4=; b=PhYFE9kqShb7CUr4bIUk2O+SOiK1N5vR0bf+0MoRA98ahvtgmp8+LxVuEazD9QtCTG qk8jbmdn+PhKplXo9HobvqN80T8Npljq6fBmFUKfW9ZWMHxZTN6brvSK/bNgSCwdK+H4 af+NpPg3mF8FTDnZ/q6e7nPAmzQ5k6zC6OjlV10qSR97VP6AXG7s4o7Z6PsUllk+K1TI apKczucXf0z402achEvCQ3lXqvv6TXsTYKgxQdOA6+ujH2SfcMi5x6qgxp1ikMddoRM/ XpBuIJeqKw2EK9XK8Ts20mpakUSaemLUlzNVe3iU46EEgRp3urc0V8AcgppS1xNzX+QB JwEg== X-Forwarded-Encrypted: i=1; AJvYcCUELSrs/xHgDTSYDAUO5dHeZkuziUQJOkd/55OaDRmY8/kCz/aRl6iWAiowY0zy/5b0bSnQaI7ES3EVTQ==@gnu.org, AJvYcCUbLCdnpfGhk1Jgf6WYjs5WSx7aY1v163hFAGeJ2bGZkkOfcm2DOUvOxQ4JVAEejdN6ntqbhw==@gnu.org, AJvYcCViREfu+ul3zuLX08wxFCbjc0S22V16RbLCyrwU3fh2M8LowSWck4AHnwXGjdrSiTDPo6kUjBpH19XOtg==@gnu.org X-Gm-Message-State: AOJu0YxmSAMYDbUTUoVoCrgh89L6C1lGSJEXy2CGDcCQ0I/mD02xMnB0 8EGrjsRAxCz98sdxXt26DFuZREQMG70ylqBFC9HXMdI5+uk3zXiXHGCVWM5TXmh2pvnHPdtFJf+ mx2McRxXiF1K5ZYK8FRsv1Zckxl4= X-Gm-Gg: ASbGncsFNGYASudAj479wpMo0tUwE6XfiwiIN0n676pQJ1mvweOfFPA/EEliE9AtiCp 3lz+COwEPd3dVFwMS/MEDoFmHbaICPKZN X-Google-Smtp-Source: AGHT+IFWM/gn5vJIrnAEjLmkAChfwZ+kYL77ASsEuCUdzSMMO2e5JAgqr78uftJli30VR/GuGiwrka3K/DoielHihe4= X-Received: by 2002:a05:6122:4d0a:b0:514:f579:3bad with SMTP id 71dfb90a1353d-515009bd73cmr7270523e0c.9.1732376503105; Sat, 23 Nov 2024 07:41:43 -0800 (PST) In-Reply-To: <20241123163143.gFXi2D00541pia201FXiCK@xavier.telenet-ops.be> Received-SPF: pass client-ip=209.85.222.46; envelope-from=mdjurfeldt@gmail.com; helo=mail-ua1-f46.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22790 gmane.lisp.guile.user:19917 Archived-At: --00000000000015c27206279656ca Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=AFPM Maxime Devos wrote: > >Any opinions on what is best: Having a define-method* or having the > functionality in define-method itself? > > > > You can=E2=80=99t unify define-method with define-method* without making = some > arbitrary choices in some special cases (the same applies to define-metho= d* > 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=E2=80=99t have much practice w= ith > GOOPS): > > > > (define-method (f (a ) (b )) > (pk 'positional a b)) > > > > ;; what I mean is to only consider =E2=80=98foo=E2=80=99 that are of clas= s , I > don=E2=80=99t mean as default value > > (define-method (f (#:key foo )) > (pk 'keyword foo)) > > > > An ambiguous case: (f #:foo 1). This matches both the first and second > implementation. is more specific that , so this sounds > like the first method should win. But, =E2=80=98#:foo=E2=80=99 is more sp= ecific than > , so the second should win. > > > > I don=E2=80=99t know what the rule is for positional arguments (I assume = earlier > arguments are more important in case of ambiguity?). However, the same ru= le > cannot be applied to keyword arguments, since they aren=E2=80=99t positio= nal. > Consider: > > > > (define-method (g (#:key foo ) (#:key bar )) > > (pk 'integer foo)) > > > > (define-method (g (#:key bar ) (#:key foo )) > > (pk 'symbol bar)) > > > > (g #:foo 1 #:bar a) ;integer or symbol? > > (g #:bar a #:foo 1) ;does this produce the same result? > > > > Either =E2=80=98integer=E2=80=99 or =E2=80=98symbol=E2=80=99 would be app= ropriate, but it shouldn=E2=80=99t depend > on whether #:foo or #:bar is written first in the argument call. Now #:fo= o > and #:bar need to be (ideally deterministically) ordered, but any > particular ordering is somewhat arbitrary, and it=E2=80=99s a bit against= the > notion of keyword arguments =E2=80=93 orderings are more a thing for _*po= sitional*_ > arguments. > > > > Potential escape: in case of ambiguity, give up and throw some kind of > exception. Not ideal, but at least it=E2=80=99s not random, doesn=E2=80= =99t depend on how > the keyword arguments were worded, and it would be limited to keyword > methods. > > > > Best regards, > > Maime Devos > --00000000000015c27206279656ca Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Maxime,

Well, these parti= cular examples aren't valid since GOOPS doesn't allow type specifie= rs for keyword arguments. (It's the same in CLOS.) Type dispatch is don= e *only* on the required arguments.

Best regards,<= /div>
Mikael

On Sat, Nov 23, 2024 at 4:31=E2=80=AFPM Maxime De= vos <maximedevos@telenet.be> wrote:

>Any opinions on = what is best: Having a define-method* or having the functionality in define= -method itself?

<= span lang=3D"EN-GB">=C2=A0

<= span lang=3D"EN-GB">You can=E2=80=99t unify define-method with define-metho= d* without making some arbitrary choices in some special cases (the same ap= plies to define-method* too actually, and also to define-method on its own = without keyword arguments, but it needs to be considered and documented som= ewhere).

=C2=A0

Consider (please ignore syntax errors, don=E2=80=99t have much practice w= ith GOOPS):

=C2=A0

(define-method (f (a <keyword>) (b <integer>))
=C2=A0 (= pk 'positional a b))

=C2=A0

;; what I mean is to only consider =E2=80=98foo=E2=80=99 = that are of class <number>,=C2=A0 I don=E2=80=99t mean <number>= as default value

(define-method (f (#:key foo <number= >))
=C2=A0=C2=A0(pk 'keyword foo))

=C2=A0

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 w= in. But, =E2=80=98#:foo=E2=80=99 is more specific than <keyword>, so = the second should win.

=C2=A0

I don=E2=80=99t know what the rule is for positional argume= nts (I assume earlier arguments are more important in case of ambiguity?). = However, the same rule cannot be applied to keyword arguments, since they a= ren=E2=80=99t positional. Consider:

=C2=A0

(define-method (g (#:key foo <integer>) = (#:key bar <object>))

= =C2=A0 (pk 'integer foo))

=

=C2=A0

=

(define-method (g (#:key bar &l= t;symbol>) (#:key foo <object>))

=C2=A0 (pk 'symbol bar))<= /u>

=C2=A0<= /u>

(g #:foo 1 #:bar = a) ;integer or symbol?

(g #:bar a #:foo 1) ;does this produce the same result?<= /u>

=C2= =A0

Either =E2= =80=98integer=E2=80=99 or =E2=80=98symbol=E2=80=99 would be appropriate, bu= t it shouldn=E2=80=99t depend on whether #:foo or #:bar is written first in= the argument call. Now #:foo and #:bar need to be (ideally deterministical= ly) ordered, but any particular ordering is somewhat arbitrary, and it=E2= =80=99s a bit against the notion of keyword arguments =E2=80=93 orderings a= re more a thing for _positional_ arguments.

=

=C2=A0

=

Potential escape: in case of am= biguity, give up and throw some kind of exception. Not ideal, but at least = it=E2=80=99s not random, doesn=E2=80=99t depend on how the keyword argument= s were worded, and it would be limited to keyword methods.

=C2=A0

Best regards,=

Maime Devos

--00000000000015c27206279656ca--