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

Re: Reinitialization



Yow! That *was* pretty hairy. 

Well, anywy, my observations on the matter are the following:

1) 99% of the people using CLOS won't be interested in customizing
(re)initialization anyway,

2) Of the 1% that are, maybe 80% will need the fine distinctions
that the current interface provides.

So putting in 4 functions just so .8% of the people who use CLOS don't
have to go through extra hair doesn't make much sense to me.
Not to speak of the hair in your note.

Here's what I had in mind. Let's say Joe MetaObject User wants to
specialize in such a way that, indeed, some distinction between
an instance changing due to a class redefinition and due to a
CHANGE-CLASS call are distinguished. Then the following code
should do it:


(defmethod change-class ((instance joes-class) new-class)

  (with-added-methods
    (reinitialize ((object joes-class) &rest reinit-args)
       <code to deal with changes in this case, perhaps including
        call-next-method>

    )


     <code to deal with what Joe wants, including perhaps call-next-method

     (apply #'reinitialize instance joes-reinit-args)

     <further specific code>
  )
)

Now, let's say Joe wants to change around how instances are reinitialized
when a change is made through redefinition of a class. This is
somewhat trickier, but still possible:


(defmethod reinitialize ((object joes-class) &rest reinit-args)

  <do something to reinitialize when the class definition is changed>

)

(defmethod change-class ((instance joes-class) new-class

  (with-added-methods
    (reinitialize ((object joes-class) &rest reinit-args)
       <code to deal with changes only for class changing>

    )


     <code to deal with what Joe wants, including perhaps call-next-method>

     (apply #'reinitialize instance joes-reinit-args)

     <further specific code>
  )
)


Are there any other occasions when reinitialize might be called?
One might be that a programmer might want to call it directly.
In that case, its incumbent upon Joe to supply his own method
which does reinitialization according to a scheme for direct
calls, perhaps using a different name or lexically, at the top
level.

In any event, you get the idea. No flags, special variables,
functional arguments, MSG, smoke, or mirrors. Just using the
mechanisms which are already in place to do the job.


		jak