Subject: [clisp-list] CLOS: class-wide slots defined at compile-time?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Fri Feb 21 01:30:04 2003

Hi,

>> The class-prototype hack(?) may be something
>> 2) which seems to be somewhat standard in CLOS (I guess from your
>> wording),
>it's in MOP.
I found
http://www.elwoodcorp.com/alu/mop/dictionary.html
http://www.franz.com/support/documentation/6.2/doc/mop/dictionary.html
"Generic Function class-prototype class 
Returns a prototype instance of class. Whether the instance is initialized is not specified. The results are undefined if a portable program modifies the binding of any slot of prototype instance."

It says "any slot", not "any local slot". Therefore, modifying shared slots like I'd wish to do seems unportable as well.
[English: probably needs to say "slot of *a/the/this* prototype instance".

>it's better to keep the prototype inside the CLASS struct.
>class may be redefined &c.
>we may create the prototype on demand.
considering class redefinition: forget the hash-table I suggested. Just create a new object for each invocation of class-prototype. W.r.t. redefinitions, with or without a table, the class-prototype instance may be subject to update-instance-for-redefined-class, like all other instances.
So I still don't see the necessity to spend a slot for this (supposedly) seldomly used thing. The MOP does not specify that there's a unique class-prototype instance for each class.

Maybe they said "consequences unspecified" because they wanted to leave it open whether this prototype would actually be considered by update-instance-for-redefined-class. Consider how user code (custom defmethod update-instance ...) may fail when encountering an instance with no initialized (bound) local slot. That might not meet the programmer's expectations. Conversely, I can't imagine how the local slots could possibly be initialized, since there's no way to obtain possibly required initargs.
All in all, this same problem w.r.t. redefinitions also applies to reading slots.

What about:
(defun class-prototype (class) (allocate-instance class))
;TODO class-prototype as a GF
However, this is not compliant, since "This generic function signals an error if class has not been finalized" whereas allocate-instance would finalize when needed.

However, allocate-instance may be all I need.

Are there compiler restrictions on using defclass and make/allocate-instance in the same file?
http://www.lispworks.com/reference/HyperSpec/Body/03_bbc.htm
does not indicate something like this. I may need eval-when around my defclass forms.

Regards,
	Jorg Hohle.

---

From: Sam Steingold <[email-masked]>
Date: Fri Feb 21 08:48:15 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] CLOS: class-wide slots defined at compile-time?"
> * Sent on Fri, 21 Feb 2003 10:27:34 +0100
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>

not in CLISP.
you may need to tweak pcl::*defclass-times*, pcl::*defgeneric-times*
and pcl::*defmethod-times* for CMUCL and SBCL.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Single tasking: Just Say No.

---

From: Christophe Rhodes <[email-masked]>
Date: Fri Feb 21 11:51:05 2003

> and pcl::*defmethod-times* for CMUCL and SBCL.

For what it's worth, those variables do not exist in SBCL, and as long
as the class is defined before it is used there is no problem with
making an instance of a class in the same file.

Cheers,

Christophe
--  
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)