[closer-devel] two defun's MIA

Pascal Costanza pc at p-cos.net
Tue Oct 31 22:38:01 UTC 2006


On 31 Oct 2006, at 22:24, Attila Lendvai wrote:

>
> hi!
>
> i've updated computed-class with custom generated accessors and in  
> the process on making it more standard compliant i was looking for  
> this (#:initialize-class-metaobject #:reinitialize-class- 
> metaobject) piece of code that was once in aspectl but i can't find  
> it anywhere. where are they?
>

They are gone. (Well that's kind of obvious... ;)

They are gone for a reason: They were too complicated and achieved  
very little. I didn't completely understand the effects of forward- 
referenced-class at that time when I have written them and  
overestimated their potential bad effects on class initialization /  
reinitialization.

The standard idiom for class initialization / reinitialization when  
you want to add your own default topmost object (like standard-object  
and funcallable-standard-object for standard-class and funcallable- 
standard-class) is this:

(defmethod initialize-instance :around
   ((class my-class) &rest initargs
    &key direct-superclasses)
   (declare (dynamic-extent initargs))
   (if (loop for class in direct-superclasses
             thereis (subtypep class (find-class 'my-object)))

      ;; 'my-object is already one of the (indirect) superclasses
      (call-next-method)

      ;; 'my-object is not one of the superclasses, so we have to add it
      (apply #'call-next-method
             class
             :direct-superclasses
             (append direct-superclasses
                     (list (find-class 'my-object)))
             initargs)))



(defmethod reinitialize-instance :around
   ((class my-class) &rest initargs
    &key (direct-superclasses '() direct-superclasses-p))
   (declare (dynamic-extent initargs))
   (if direct-superclasses-p

     ;; if direct superclasses are explicitly passed
     ;; this is exactly like above
     (if (loop for class in direct-superclasses
               thereis (subtypep class (find-class 'my-object)))
        (call-next-method)
        (apply #'call-next-method
               class
               :direct-superclasses
               (append direct-superclasses
                       (list (find-class 'my-object)))
               initargs))

     ;; if direct superclasses are not explicitly passed
     ;; we _must_ not change anything
     (call-next-method)))


This idiom doesn't work in some CLOS implementations, but when you  
use Closer to MOP, the respective problems are fixed, so you can use  
this idiom in all implementations that Closer to MOP supports.


I hope this helps.


Pascal

-- 
Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/closer-devel/attachments/20061031/f74377ca/attachment.html>


More information about the closer-devel mailing list