unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ?
@ 2010-12-02  7:06 Nala Ginrut
  2010-12-02 17:40 ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Nala Ginrut @ 2010-12-02  7:06 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]

Hi, everybody!
I got a question while I'm trying GOOPS, here is some example code pieces:
;;guile code
(define-class <test> ()
  (cache #:init-form 0)
  (tt #:init-form 1
      #:allocation #:virtual
      #:slot-set! (lambda (o v)
                       (slot-set! o 'cache
                                     (cons v (slot-ref o 'cache)))
                        );;end lambda
      #:slot-ref (lambda (o) #f)  ;; ***FIXME: can I use generic "slot-ref"
without re-define here??
  ..........
;;guile code end
-----------------------------------------------

Please notice the line with "***FIXME" .I know that the "slot-set!" and
"slot-ref" must be re-defined under "#:allocation #:virtual", but can I find
some approach that just re-define one of them? Maybe I'll need a
modified(with overload) "slot-set!", but I need a generic "slot-ref" in some
circumstance. I don't know how to do. If I called "slot-ref" in the
re-defination of "slot-ref", that would be recursively infinite.
How can I deal with this? Any help will be appreciated, thanks!

[-- Attachment #2: Type: text/html, Size: 1327 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ?
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Neil Jerram @ 2010-12-02 17:40 UTC (permalink / raw)
  To: Nala Ginrut; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1355 bytes --]

On 2 December 2010 07:06, Nala Ginrut <nalaginrut@gmail.com> wrote:

> Hi, everybody!
> I got a question while I'm trying GOOPS, here is some example code pieces:
> ;;guile code
> (define-class <test> ()
>   (cache #:init-form 0)
>   (tt #:init-form 1
>       #:allocation #:virtual
>       #:slot-set! (lambda (o v)
>                        (slot-set! o 'cache
>                                      (cons v (slot-ref o 'cache)))
>                         );;end lambda
>       #:slot-ref (lambda (o) #f)  ;; ***FIXME: can I use generic "slot-ref"
> without re-define here??
>   ..........
> ;;guile code end
> -----------------------------------------------
>
> Please notice the line with "***FIXME" .I know that the "slot-set!" and
> "slot-ref" must be re-defined under "#:allocation #:virtual", but can I find
> some approach that just re-define one of them? Maybe I'll need a
> modified(with overload) "slot-set!", but I need a generic "slot-ref" in some
> circumstance. I don't know how to do. If I called "slot-ref" in the
> re-defination of "slot-ref", that would be recursively infinite.
> How can I deal with this? Any help will be appreciated, thanks!
>

I'm not sure this is what you mean... but yes, your #:slot-ref lambda can do
a slot-ref on normal slots, such as "cache", e.g.:

   #:slot-ref (lambda (o) (car (slot-ref o 'cache)))

Neil

[-- Attachment #2: Type: text/html, Size: 1779 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ?
  2010-12-02 17:40 ` Neil Jerram
@ 2010-12-03  0:52   ` Nala Ginrut
  2010-12-03  1:42     ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Nala Ginrut @ 2010-12-03  0:52 UTC (permalink / raw)
  To: Neil Jerram; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 679 bytes --]

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?

[-- Attachment #2: Type: text/html, Size: 837 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ?
  2010-12-03  0:52   ` Nala Ginrut
@ 2010-12-03  1:42     ` Neil Jerram
  2010-12-03  2:13       ` Nala Ginrut
  0 siblings, 1 reply; 7+ messages in thread
From: Neil Jerram @ 2010-12-03  1:42 UTC (permalink / raw)
  To: Nala Ginrut; +Cc: guile-user

[-- 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 --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ?
  2010-12-03  1:42     ` Neil Jerram
@ 2010-12-03  2:13       ` Nala Ginrut
  2010-12-03 18:22         ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Nala Ginrut @ 2010-12-03  2:13 UTC (permalink / raw)
  To: Neil Jerram; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 263 bytes --]

yeah~you hit it precisely!
But I'm not sure if I modified the slot-seting call ,the result is all
slot-set! procedure would be effected? That's terrible.
If there isn't any existed solution, I'd better look into the code and do
some hacking.
Thank you very much!

[-- Attachment #2: Type: text/html, Size: 295 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ?
  2010-12-03  2:13       ` Nala Ginrut
@ 2010-12-03 18:22         ` Neil Jerram
  2010-12-12  9:42           ` nalaginrut
  0 siblings, 1 reply; 7+ messages in thread
From: Neil Jerram @ 2010-12-03 18:22 UTC (permalink / raw)
  To: Nala Ginrut; +Cc: Neil Jerram, guile-user

Nala Ginrut <nalaginrut@gmail.com> writes:

> yeah~you hit it precisely!
> But I'm not sure if I modified the slot-seting call

I'm not clear what you mean by that.

> ,the result is all
> slot-set! procedure would be effected?

No, that's not the case for either of my suggestions.

If you invented something like `#:allocation #:custom-setter', it would
only apply to slots that had `#:allocation #:custom-setter' in their
slot definition.

Regards,
        Neil



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: GOOPS:Can I just overload "slot-set!" under #:virtual and let alone "slot-ref" ?
  2010-12-03 18:22         ` Neil Jerram
@ 2010-12-12  9:42           ` nalaginrut
  0 siblings, 0 replies; 7+ messages in thread
From: nalaginrut @ 2010-12-12  9:42 UTC (permalink / raw)
  To: Neil Jerram; +Cc: Neil Jerram, guile-user

> Nala Ginrut <nalaginrut@gmail.com> writes:
> 
> > yeah~you hit it precisely!
> > But I'm not sure if I modified the slot-seting call
> 
> I'm not clear what you mean by that.

yes, I don't need a "#:allocation #:virtual" actually, I want a
customised "slot-set!" but a no-modified "slot-ref" while I'm reading
the value. I mean you understood my problem. 


> > ,the result is all
> > slot-set! procedure would be effected?
> 
> No, that's not the case for either of my suggestions.
> 
> If you invented something like `#:allocation #:custom-setter', it would
> only apply to slots that had `#:allocation #:custom-setter' in their
> slot definition.
> 
> Regards,
>         Neil

I considered this kind of solution could be more complicated, so I just
modify my code to end this problem for a while. But I'd better go deep
into the meta-class sometime.
Thank you!

-- 
GNU Powered it
GPL Protected it
GOD Blessed it

HFG - NalaGinrut




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-12-12  9:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2010-12-03  2:13       ` Nala Ginrut
2010-12-03 18:22         ` Neil Jerram
2010-12-12  9:42           ` nalaginrut

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).