This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: closures for GOOPS privates
Hello,
I've been using yasos, but since goops is The Guile
Object System I figured I'd start using it.
Yasos is a "classless" system (check out the slib documentation for
more, I'm not an expert) so each object has a specific instantiation
routine. One of the tricks is to wrap private data fields up into a
closure.
For instance (a silly example). This yasos object contains 2 private
slots are used to calculate the value of "a-b". They can be set, but
not accessed individually.
(define make-mine
(let ((a 1) (b 2))
(lambda ()
(object
((a-b self) (- a b)
((a! self val) (set! a val))
((b! self val) (set! b val)))))))
The reason I asked is there has been a claim that goops doesn't
support private fields. But, if I understand your second example,
then I do this in goops like so:
(define-generic a-b)
(define-generic a!)
(define-generic b!)
(define <a-b>
(let ((local-a (make-accessor 'a))
(local-b (make-accessor 'b)))
(define-method a-b ((obj <a-b>) (- (a obj) (b obj)))
(define-method a! ((obj <a-b>) (v <number>)) (set! (a obj) v))
(define-method b! ((obj <a-b>) (v <number>)) (set! (b obj) v))
(class ()
(local-a #:accessor a #init-value 1)
(local-b #:accessor b #init-value 2))))
This means that goops does have data hiding independent of any module
system. That is great. I guess the data can still be reached with
slot-ref, but who cares...
I can see I need to spend a few hours and run goops through it's
paces.
Thanks,
Clark