guile-devel
[Top][All Lists]
Advanced

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

Re: Keywords in GOOPS methods


From: Mikael Djurfeldt
Subject: Re: Keywords in GOOPS methods
Date: Thu, 21 Nov 2024 21:33:43 +0100

(I will of course add proper documentation in the manual, etc.)

On Thu, Nov 21, 2024 at 9:33 PM Mikael Djurfeldt <mikael@djurfeldt.com> wrote:
Since there are no comments, I'm inclined to apply this patch. I will do that on Sunday if there are no comments before that.

Maybe I should first give a motivating example: guile-mqtt consists of a thin wrapper over NYACC-generated code. There, I use a coding pattern that I tend to use in cases where methods need keyword arguments:

(define-method (subscribe (client <mosquitto-client>) (topic <string>) . args)
  (define* (subscribe #:key (qos 0))
    (mosquitto_subscribe (mosq client) %null-pointer topic qos))
  (apply subscribe args))

With the change I propose, this can be written:

(define-method (subscribe (client <mosquitto-client>) (topic <string>) #:key (qos 0))
  (mosquitto_subscribe (mosq client) %null-pointer topic qos)))

with the same resulting semantics.

There is one question that I'd like people to think about, though: In my patch I have adhered to the close relationship with CLOS, where defmethod takes keyword, optional and rest arguments similar to Guile's define*, and extended the method syntax itself. As an alternative, we could let the current method syntax stay as is and implement new define-method* and method* syntax. In some ways this would be cleaner, for example from a backward compatibility perspective. On the other hand it might feel like overkill to have so much syntax. Implementation and performance wise it shouldn't matter much how we choose to do, except that adding define-method* and method* of course adds more code to the implementation...

Best regards,
Mikael

On Tue, Nov 19, 2024 at 5:41 PM Mikael Djurfeldt <mikael@djurfeldt.com> wrote:
Hi all,

I've implemented support for keyword arguments (corresponding to define* and lambda*) in GOOPS. The functionality is similar to that of CLOS (which also has keyword in methods) in that dispatch is not done on the keyword part.

You can find the changes in the goops-keyword branch at https://github.com/mdjurfeldt/guile/tree/goops-keyword or in the included patch.

Comments?

Best regards,
MIkael


reply via email to

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