public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* accessor, getter setter for kawa class
@ 2023-10-16 11:18 Damien Mattei
  2023-10-16 11:41 ` Ἀλκείδης FP
  0 siblings, 1 reply; 4+ messages in thread
From: Damien Mattei @ 2023-10-16 11:18 UTC (permalink / raw)
  To: kawa mailing list

are there predefined getter or setter for a field of a kawa class?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: accessor, getter setter for kawa class
  2023-10-16 11:18 accessor, getter setter for kawa class Damien Mattei
@ 2023-10-16 11:41 ` Ἀλκείδης FP
  2023-10-16 13:30   ` Damien Mattei
  0 siblings, 1 reply; 4+ messages in thread
From: Ἀλκείδης FP @ 2023-10-16 11:41 UTC (permalink / raw)
  To: Damien Mattei; +Cc: kawa mailing list

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

Hi Damien.

AFAIK, there aren't such predefinded accesors in Kawa classes.

To achieve the same goal I usually do one of the following:

a) Leave the field as public and use it directly.

b) Define a parent class (abstract or not) in Java and use Lombok
annotations (@Getter, @Setter, @Data, etc)

Greetings.

El lun., 16 de octubre de 2023 6:19, Damien Mattei via Kawa <
kawa@sourceware.org> escribió:

> are there predefined getter or setter for a field of a kawa class?
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: accessor, getter setter for kawa class
  2023-10-16 11:41 ` Ἀλκείδης FP
@ 2023-10-16 13:30   ` Damien Mattei
  2023-10-16 16:43     ` Alcides Flores
  0 siblings, 1 reply; 4+ messages in thread
From: Damien Mattei @ 2023-10-16 13:30 UTC (permalink / raw)
  To: Ἀλκείδης FP; +Cc: kawa mailing list

hello Ἀλκείδης

in fact, as written in the manual , a lot of Guile GOOPS procedure are
ported to Kawa, like slot-ref and this give this code:

(define (matrix-v M)
  (slot-ref M 'v))

to have the same getter than in Guile or Racket for a matrix class:

(define-simple-class matrix ()

  (v::vector)

  ((*init* (vParam::vector))
   (set! v vParam))

  )

(matrix-v M)
#(#(0 1 2) #(1 2 3))


On Mon, Oct 16, 2023 at 1:41 PM Ἀλκείδης FP <alcides.fp@gmail.com> wrote:
>
> Hi Damien.
>
> AFAIK, there aren't such predefinded accesors in Kawa classes.
>
> To achieve the same goal I usually do one of the following:
>
> a) Leave the field as public and use it directly.
>
> b) Define a parent class (abstract or not) in Java and use Lombok annotations (@Getter, @Setter, @Data, etc)
>
> Greetings.
>
> El lun., 16 de octubre de 2023 6:19, Damien Mattei via Kawa <kawa@sourceware.org> escribió:
>>
>> are there predefined getter or setter for a field of a kawa class?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: accessor, getter setter for kawa class
  2023-10-16 13:30   ` Damien Mattei
@ 2023-10-16 16:43     ` Alcides Flores
  0 siblings, 0 replies; 4+ messages in thread
From: Alcides Flores @ 2023-10-16 16:43 UTC (permalink / raw)
  To: Damien Mattei
  Cc: Ἀλκείδης FP, kawa mailing list


[-- Attachment #1.1: Type: text/plain, Size: 1347 bytes --]


*Hello Damien.*

Thanks for pointing them out and remembering me of those ones.
I guess I misunderstood the meaning of the "predefined" word as mentioned before.

Well, yes indeed the /generic/ accessor & mutator procedures (=slot-ref,slot-set!=)
work very well with public fields, which is the default access modifier in
Kawa anyway.

But AFAIK they don't work with private or protected fields, as it is
the case when using Java frameworks or libraries that usually follow a
more "traditional"/Java-like OOP-Style in which fields are almost
allways private/protected and hence require proper accessors/mutators.

Therefore if your use case is not like this, they should work and serve
you well.

#+begin_src scheme
;; Defining a class with a private field
(define-simple-class MyKlass ()
  (v::vector #:access 'private)
  ((*init* (vparm::vector))
   (set! v vparm)))

;; Trying to access the private field throws exception
(! m1 (MyKlass #(1 2 3)))
(slot-ref m1 'v)

java.lang.RuntimeException: no such field v in my-klass
	at gnu.kawa.reflect.SlotGet.getSlotValue(SlotGet.java:188)
	at atInteractiveLevel-3.run(tty:3)
	at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:290)
	at kawa.Shell.run(Shell.java:300)
	at kawa.Shell.run(Shell.java:183)
	at kawa.repl.processArgs(repl.java:724)
	at kawa.repl.main(repl.java:830)
#+end_src

*Greetings.*


[-- Attachment #2: Type: text/plain, Size: 1154 bytes --]



-- 
Alcides Flores.


Lunae, oct 16 2023, Damien Mattei scripsit:

> hello Ἀλκείδης
>
> in fact, as written in the manual , a lot of Guile GOOPS procedure are
> ported to Kawa, like slot-ref and this give this code:
>
> (define (matrix-v M)
>   (slot-ref M 'v))
>
> to have the same getter than in Guile or Racket for a matrix class:
>
> (define-simple-class matrix ()
>
>   (v::vector)
>
>   ((*init* (vParam::vector))
>    (set! v vParam))
>
>   )
>
> (matrix-v M)
> #(#(0 1 2) #(1 2 3))
>
>
> On Mon, Oct 16, 2023 at 1:41 PM Ἀλκείδης FP <alcides.fp@gmail.com> wrote:
>>
>> Hi Damien.
>>
>> AFAIK, there aren't such predefinded accesors in Kawa classes.
>>
>> To achieve the same goal I usually do one of the following:
>>
>> a) Leave the field as public and use it directly.
>>
>> b) Define a parent class (abstract or not) in Java and use Lombok annotations (@Getter, @Setter, @Data, etc)
>>
>> Greetings.
>>
>> El lun., 16 de octubre de 2023 6:19, Damien Mattei via Kawa <kawa@sourceware.org> escribió:
>>>
>>> are there predefined getter or setter for a field of a kawa class?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-16 16:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-16 11:18 accessor, getter setter for kawa class Damien Mattei
2023-10-16 11:41 ` Ἀλκείδης FP
2023-10-16 13:30   ` Damien Mattei
2023-10-16 16:43     ` Alcides Flores

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).