From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: Is there any approach to define "private" vars in GOOPS? Date: Fri, 01 Apr 2011 23:55:03 +0100 Message-ID: <871v1ly43c.fsf@ossau.uklinux.net> References: <1299638259.2577.5.camel@Renee-desktop> <87d3m0llza.fsf@ossau.uklinux.net> <1299662845.2577.82.camel@Renee-desktop> <1299663423.2577.86.camel@Renee-desktop> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1301698564 28612 80.91.229.12 (1 Apr 2011 22:56:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 1 Apr 2011 22:56:04 +0000 (UTC) Cc: Guile To: NalaGinrut@gmail.com Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Apr 02 00:55:57 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5nG0-0003eP-RF for guile-user@m.gmane.org; Sat, 02 Apr 2011 00:55:57 +0200 Original-Received: from localhost ([127.0.0.1]:38672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q5nG0-0007RX-Fn for guile-user@m.gmane.org; Fri, 01 Apr 2011 18:55:56 -0400 Original-Received: from [140.186.70.92] (port=56128 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q5nFw-0007PE-8T for guile-user@gnu.org; Fri, 01 Apr 2011 18:55:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q5nFt-0005T3-M2 for guile-user@gnu.org; Fri, 01 Apr 2011 18:55:52 -0400 Original-Received: from mail3.uklinux.net ([80.84.72.33]:56641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q5nFt-0005IC-GK for guile-user@gnu.org; Fri, 01 Apr 2011 18:55:49 -0400 Original-Received: from arudy (unknown [78.145.25.179]) by mail3.uklinux.net (Postfix) with ESMTP id E2E4A1F665F; Fri, 1 Apr 2011 23:55:05 +0100 (BST) Original-Received: from neil-laptop (unknown [192.168.11.4]) by arudy (Postfix) with ESMTP id C317C38013; Fri, 1 Apr 2011 23:55:04 +0100 (BST) In-Reply-To: <1299663423.2577.86.camel@Renee-desktop> (nalaginrut@gmail.com's message of "Wed, 09 Mar 2011 17:37:03 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 80.84.72.33 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8571 Archived-At: nalaginrut 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