[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is there any approach to define "private" vars in GOOPS?
From: |
Neil Jerram |
Subject: |
Re: Is there any approach to define "private" vars in GOOPS? |
Date: |
Fri, 01 Apr 2011 23:55:03 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
nalaginrut <address@hidden> writes:
> Sorry I think the "update score" is a fake problem. It can be solved by
> #:allocation #:virtual.
> But I still want to talk this topic: "How to hide the critical
> property?"
With apologies for the late reply...
I guess something like this (untested):
(define valid-score-update #f)
(define slot-setter-if-valid-scope #f)
(let ((valid-scope #f))
(set! valid-score-update
(lambda (player newscore)
(set! valid-scope #t)
(slot-set! player 'score newscore)
(set! valid-scope #f)))
(set! slot-setter-if-valid-scope
(lambda (obj new-val)
(or valid-scope
(error "Not in valid scope!"))
(set! (score obj) new-val))))
Then use `valid-score-update' in the definition of the score-update
method, and `slot-setter-if-valid-scope' as the #:slot-set! option of
your virtual 'score slot.
I've assumed that (score obj) provides the real underlying storage for
the virtual slot; it could be a (make-object-property), for example.
Unfortunately I'd say this adds up to an over-contrived solution; but
hopefully it's still useful to show how it _could_ be done.
Regards,
Neil
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Is there any approach to define "private" vars in GOOPS?,
Neil Jerram <=