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: GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ? Date: Fri, 3 Dec 2010 01:42:19 +0000 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=000e0cd32c20283fab049677a6db X-Trace: dough.gmane.org 1291340576 7728 80.91.229.12 (3 Dec 2010 01:42:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Dec 2010 01:42:56 +0000 (UTC) Cc: guile-user@gnu.org To: Nala Ginrut Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Dec 03 02:42:51 2010 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 1POKfb-0007nX-OQ for guile-user@m.gmane.org; Fri, 03 Dec 2010 02:42:44 +0100 Original-Received: from localhost ([127.0.0.1]:40054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POKfU-0003bP-No for guile-user@m.gmane.org; Thu, 02 Dec 2010 20:42:36 -0500 Original-Received: from [140.186.70.92] (port=58265 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POKfG-0003b1-Ju for guile-user@gnu.org; Thu, 02 Dec 2010 20:42:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POKfF-0006s0-0T for guile-user@gnu.org; Thu, 02 Dec 2010 20:42:22 -0500 Original-Received: from mail-px0-f169.google.com ([209.85.212.169]:41000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POKfE-0006rg-Ng for guile-user@gnu.org; Thu, 02 Dec 2010 20:42:20 -0500 Original-Received: by pxi12 with SMTP id 12so3780733pxi.0 for ; Thu, 02 Dec 2010 17:42:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=EEItKJMHF1hvDOIUhXJ81wzyDzdS6lH43ahdarn7LZk=; b=jwNrnBq10j1YNUOdxL5HwFUYia3WDiwZSSwUy5C+ImbsWGacIpofHfk3KNryG5J6qz kjQGaXfDLtHEkfFVHCnLx3FuP4omCpvA/O7W+Elep+FCppJb+jofaI7Vav8s4Q+WKJX0 1Ly+pOzB7UkOdYfUHYAl7Vkt+7jca/yKXeDSo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=OXaBG0QlP8+vsmHR87B+xI7hCZkYHLWTcy2Wo4bQTY1tuM2FpJG+1n4QiRO1zqVxZL Qjtn18DM92pBMnB3zYJ8Xpzq/9urtawZzIgFw52OPjVS9NPsUH1xi6yhxK6ROZxZiYK9 jOsDifdqYjcq2l6Lw5pG+cM8SAUmi0VkvQcvA= Original-Received: by 10.142.229.8 with SMTP id b8mr1264519wfh.20.1291340539772; Thu, 02 Dec 2010 17:42:19 -0800 (PST) Original-Received: by 10.143.41.13 with HTTP; Thu, 2 Dec 2010 17:42:19 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:8282 Archived-At: --000e0cd32c20283fab049677a6db Content-Type: text/plain; charset=ISO-8859-1 On 3 December 2010 00:52, Nala Ginrut wrote: > thanks, but my question is something like this: > ... > (cache ... #:slot-ref (lambda (o) (slot-ref o 'cache)) ...) ;; ERROR > ... > (sunday ... #:slot-ref (lambda (o) (slot-ref o 'cache)) ...) ;; That's OK > > I could call "(slot-ref o 'cache)" in other slot except "cache", but what > should I do if I need to use "(slot-ref o 'cache)" in the "cache" > definition? > I used it directly and got "stack overflow". I think it may cause infinite > recursive. > Actually my question can be described more explicitly: "Can I just > re-define "slot-ref" or "slot-set!" any one of them but NOT both?" > Sometimes I may need a re-defined "slot-set!" but I expect to let alone > "slot-ref". > Anybody catch my mind? > Yes, I think so. The thing about #:allocation #:virtual is that there then isn't any storage for that slot name, at all, in instances of the relevant class. So clearly a normal slot-ref can't work. But I think I understand what you want: you don't actually want #:allocation #:virtual, but you do want some kind of customised processing when setting a slot's value; and you don't need to do anything special when reading the value. Is that right? If so, the simplest solution is to define your slot-setting call as something other than plain slot-set!, but which uses slot-set! internally after it has done the custom processing. You could also define a new kind of #:allocation to implement the behaviour you're looking for, and a metaclass for classes that can contain that kind of slots, and write a compute-get-n-set method for that metaclass ... but that's quite a bit more complex. Regards, Neil --000e0cd32c20283fab049677a6db Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Yes, I think so.

The thing about = #:allocation #:virtual is that there then isn't any storage for that sl= ot name, at all, in instances of the relevant class.=A0 So clearly a normal= slot-ref can't work.

But I think I understand what you want: you don't actually want #:a= llocation #:virtual, but you do want some kind of customised processing whe= n setting a slot's value; and you don't need to do anything special= when reading the value.=A0 Is that right?

If so, the simplest solution is to define your slot-setting call as som= ething other than plain slot-set!, but which uses slot-set! internally afte= r it has done the custom processing.

You could also define a new kin= d of #:allocation to implement the behaviour you're looking for, and a = metaclass for classes that can contain that kind of slots, and write a comp= ute-get-n-set method for that metaclass ... but that's quite a bit more= complex.

Regards,
=A0=A0=A0=A0=A0=A0=A0 Neil

--000e0cd32c20283fab049677a6db--