unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
To: NalaGinrut@gmail.com
Cc: Guile <guile-user@gnu.org>
Subject: Re: Is there any approach to define "private" vars in GOOPS?
Date: Fri, 01 Apr 2011 23:55:03 +0100	[thread overview]
Message-ID: <871v1ly43c.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <1299663423.2577.86.camel@Renee-desktop> (nalaginrut@gmail.com's message of "Wed, 09 Mar 2011 17:37:03 +0800")

nalaginrut <nalaginrut@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



  parent reply	other threads:[~2011-04-01 22:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09  2:37 Is there any approach to define "private" vars in GOOPS? nalaginrut
2011-03-09  8:46 ` Neil Jerram
2011-03-09  9:27   ` nalaginrut
2011-03-09  9:37     ` nalaginrut
2011-03-09 22:19       ` Andy Wingo
2011-04-01 22:55       ` Neil Jerram [this message]
2011-03-09  9:46   ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871v1ly43c.fsf@ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=NalaGinrut@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).