From: Neil Jerram <neiljerram@gmail.com>
To: Nala Ginrut <nalaginrut@gmail.com>
Cc: guile-user@gnu.org
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 [thread overview]
Message-ID: <AANLkTi=kqL_PqkzSSYhRF-LjqEm0CmWnQbRufkAWMR+s@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimu=hV7o4M=_2UsHNV=AB8whT9sTdiqT4BLh_Xz@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1699 bytes --]
On 3 December 2010 00:52, Nala Ginrut <nalaginrut@gmail.com> 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
[-- Attachment #2: Type: text/html, Size: 2205 bytes --]
next prev parent reply other threads:[~2010-12-03 1:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-02 7:06 GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ? Nala Ginrut
2010-12-02 17:40 ` Neil Jerram
2010-12-03 0:52 ` Nala Ginrut
2010-12-03 1:42 ` Neil Jerram [this message]
2010-12-03 2:13 ` Nala Ginrut
2010-12-03 18:22 ` Neil Jerram
2010-12-12 9:42 ` nalaginrut
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='AANLkTi=kqL_PqkzSSYhRF-LjqEm0CmWnQbRufkAWMR+s@mail.gmail.com' \
--to=neiljerram@gmail.com \
--cc=guile-user@gnu.org \
--cc=nalaginrut@gmail.com \
/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).