public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Alcides Flores <alcides.fp@gmail.com>
To: Damien Mattei <damien.mattei@gmail.com>
Cc: "Ἀλκείδης FP" <alcides.fp@gmail.com>,
	"kawa mailing list" <kawa@sourceware.org>
Subject: Re: accessor, getter setter for kawa class
Date: Mon, 16 Oct 2023 10:43:03 -0600	[thread overview]
Message-ID: <87fs2ajz6w.fsf@gmail.com> (raw)
In-Reply-To: <CADEOadcPpzSKAW5t=ZOUMJ7RyrJHToa5nXbQvfSwKiPt4SJRyA@mail.gmail.com> (Damien Mattei's message of "Mon, 16 Oct 2023 15:30:55 +0200")


[-- 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?

      reply	other threads:[~2023-10-16 16:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16 11:18 Damien Mattei
2023-10-16 11:41 ` Ἀλκείδης FP
2023-10-16 13:30   ` Damien Mattei
2023-10-16 16:43     ` Alcides Flores [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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fs2ajz6w.fsf@gmail.com \
    --to=alcides.fp@gmail.com \
    --cc=damien.mattei@gmail.com \
    --cc=kawa@sourceware.org \
    /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).