From: Larry Clapp
Subject: how to access a shared slot without an instance?
Date: 
Message-ID: <113dva.jkh.ln@127.0.0.1>
Greetings, all,

Can you access a slot defined with :class allocation without having an
instance of the class?  For example, given only

    (defclass c ()
      ((g :allocation :class)))

and no instances, how would you get at g?  Can you even do this?

Background: I've started doing exercises in Bruce Eckel's _Thinking in
Java_ in Java and in Lisp, in an attempt to learn both better, and
compare the two.  One of them[1] uses a static class member.  I've
looked in all the (to me) obvious places in the Hyperspec and in
cltl2, and Googled for "slot-value allocation :class"[2], and found
nothing that will give me access to a shared slot without having an
object of the class.  CLHS section 7.5.1 says "Defining a shared slot
immediately creates a slot", so I thought, perhaps, a method exists to
retrieve the value of the slot immediately.

I do not mean to imply that Common Lisp should allow this, I just want
to know how, if it does.

Thanks!

-- Larry


[1] Chapter 2, exercise 6
[2] though I didn't read all 715 links returned ...



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

From: Kenny Tilton
Subject: Re: how to access a shared slot without an instance?
Date: 
Message-ID: <3E1A1AFB.4090405@nyc.rr.com>
Not sure if this will work, but of the top of my head:

(finalize-inheritance (find-class 'xxx))
(my-class-slot (class-prototype (find-class 'xxx)))


-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
  the bath water is cold." -- Lorraine Lee Cudmore
From: Pascal Costanza
Subject: Re: how to access a shared slot without an instance?
Date: 
Message-ID: <avd71u$613$1@newsreader2.netcologne.de>
Larry Clapp wrote:
> Greetings, all,
> 
> Can you access a slot defined with :class allocation without having an
> instance of the class?  For example, given only
> 
>     (defclass c ()
>       ((g :allocation :class)))
> 
> and no instances, how would you get at g?  Can you even do this?

AFAIK there is no standard way to access class variables without an 
instance, but usually the MOP provides a class-prototype that you can 
use as a kind of "dummy" instance.


Pascal

-- 
Given any rule, however �fundamental� or �necessary� for science, there 
are always circumstances when it is advisable not only to ignore the 
rule, but to adopt its opposite. - Paul Feyerabend
From: Steven M. Haflich
Subject: Re: how to access a shared slot without an instance?
Date: 
Message-ID: <YFqS9.1026$1R6.44011723@newssvr15.news.prodigy.com>
Pascal Costanza wrote:

> AFAIK there is no standard way to access class variables without an 
> instance, but usually the MOP provides a class-prototype that you can 
> use as a kind of "dummy" instance.

This is correct.

While we're on the subject, it is worthwhile to caution beginners
about a cerftain common programming error when using class
prototypes, or writing complex instance initialization code.
It is common to find code like this:

(defclass frob (...)
   (...
    (name :accessor name :initarg :name)
    ...))

(defmethod print-object ((f frob) (s stream))
   (print-unreadable-object (f s :type t)
     (princ (name f) s)))

The problem with this print-object method is that it makes
unprintable any instances have the name slot unbound.  This is
a pain when they show up in the debugger.  It is much better
to code conservatively like this:

(defmethod print-object ((f frob) (s stream))
   (print-unreadable-object (f s :type t)
     (princ (ignore-errors (name f)) s)))

Doing so can save a lot of grief when debugging, depending on
the implementation.
From: Larry Clapp
Subject: Re: how to access a shared slot without an instance?
Date: 
Message-ID: <q4heva.c63.ln@127.0.0.1>
Thanks Kenny, Pascal, and Steven, for your responses.

-- Larry



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----