[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: access slot of a class
|
From: |
Mikael Djurfeldt |
|
Subject: |
Re: access slot of a class |
|
Date: |
Tue, 21 Nov 2023 00:27:21 +0100 |
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.mattei@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
>
- access slot of a class, Damien Mattei, 2023/11/20
- Re: access slot of a class,
Mikael Djurfeldt <=
- Message not available