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

Re: Reinitialization



I liked Dick's variation on our proposal; that is, I like using a function
rather than a flag for variation.  I also support his proposed addition to
with-added-methods of an option to specify the generic function.

However, there is a bug in the proposal.  Since users never call class-changed
or update-instance-structure (only the system does), there is no way to change
the call, and shared-initialize will always be used (so why have an argument).

Here are two proposals to fix the bug, neither of which I like a lot, though I
prefer the first.

1) Have a generic function compute-initialization-function which returns
a function to use:


(defmethod compute-initialization-function ((instance standard-object))
  #'shared-initialize) 

(defmethod initialize-instance ((instance standard-object) 
		                 &rest initargs)

  (apply (compute-initialization-function instance) instance initargs))

(defmethod update-instance-structure ((instance standard-object)
                                      added-slots
                                      discarded-slots
                                      property-list)
  (funcall (compute-initialization-function instance) instance))

etc.
  
2)  Have a special variable *initializer* with the a default value
#'shared-initialize, and use that.  For some additonal flexibility, one could
allow initialize-instance and reinitialize-instance to have keyword argument
:initializer whose default value is *initializer*.


(defmethod update-instance-structure ((instance standard-object)
                                      added-slots
                                      discarded-slots
                                      property-list)
  (funcall *initializer* instance))

(defmethod initialize-instance ((instance standard-object) 
		                &key (initializer *initializer*)
		                &rest initargs)
  (apply initializer instance initargs))