Well, if you want to set a slot explicitly using the set! form, and this is
a good way to access a slot, you can use an accessor (which internally is a
pair of a getter and a setter):

(define-class a () (x #:accessor x))

(define o (make a))

(set! (x o) 1)
(x o) -> 1

I guess you already know that you can *also* reference this slot using:

(slot-set! o 'x 2)
(slot-ref o 'x) -> 2

I should add that the accessor way fits well with GOOPS' (and CLOS')
basically rather simple concept of having objects and then generic
functions operating on them (an accessor is a generic function). Generic
functions, in turn, fit with how some Scheme procedures accept different
types of arguments and can dispatch to different actions on them.

Best regards,
Mikael

On Mon, Nov 20, 2023 at 10:33 PM Damien Mattei <damien.mat...@gmail.com>
wrote:

> hi,
> is there a way to access a slot of a class like other variable with set! ,
> Racket,Kawa allow that, but it does not seem to be the case in Guile.
>
> regards,
> damien
>

Reply via email to