|
From: Hoehle, Joerg-C. <Joe...@t-...> - 2003-02-21 09:29:29
|
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. |