[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GOOPS] Accessing a class slot

From: Ludovic Courtès
Subject: [GOOPS] Accessing a class slot
Date: Tue, 20 Jul 2004 19:21:49 +0200
User-agent: Mutt/1.5.4i [Guile enabled]


I noticed (using Guile 1.6.4) that trying to access a class-wide slot
(eg. via `class-slot-ref') before creating an instance of that class
always fails.  However, it does work once at least one instance of the
class has been created via `make'.  This behavior looks quite weird to
me:  I was expecting class-wide slots to be available right after the
class has been defined (just like C++ `static' class attributes are).

In particular, I wanted to access a class slot from within that class'
`initialize' method which turns out to not be feasible because of this.
I worked around it by creating a particular metaclass for the class in
question and then by specializing `slot-unbound' for that metaclass:

  (define-class <class-wide-slots-metaclass> (<class>))

  (define-class <the-class-with-class-wide-slots>
    #:metaclass <class-wide-slots-metaclass>)

  (define-method (slot-unbound (class <class-wide-slots-metaclass>) slot-name)
    (if (eq? <the-class-with-class-wide-slots> class)

However, although interesting, this technique is definitely not the
right way IMO.  ;-)   What do people think about this issue?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]