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