nalaginrut <nalagin...@gmail.com> 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

Reply via email to