Andrew Dorrell writes:
> Hi,
>
> I am frequently wanting to use virtual slots to "hide" the
> implementation details of certain class attributes.
>
> In order to do this I would like to be able to have variables whose
> scope is limited to but includes both slot-ref and slot-set! functions.
> I have not worked out a simple way of doing this however.
>
> Can anyone help?
>
I must admit that I'm quite sure I have not understood your problem.
Anyway, I will try to respond...
The slot-ref and slot-set! functions are normal closures. So you can use the
standard Scheme techniques to hide a value.
For instance:
(define setter! #f)
(define getter #f)
(let ((var 0))
(set! getter (lambda (o) var))
(set! setter! (lambda (o v) (set! var v))))
(define-class <foo> ()
((slot :allocation :virtual :slot-set! setter! :slot-ref getter)))
Here the setter and getter functions capture the variable var which is not
visible outside the getter and setter functions. And we have:
(define foo (make <foo>))
(slot-ref foo 'slot) ; ==> 0
(slot-set! foo 'slot 1)
(slot-ref foo 'slot) ; ==> 1
As I said, I'm not sure I respond to your question.....
-- Erick
Received on Tue Jan 13 1998 - 12:44:45 CET
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST