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

Declaration of valid initialization args. not working properly



;;; PCL doesn't seem to recognize initialization arguments 
;;; that supply arguments to an :after (or :before) method.  
;;; For example:


(defclass c1()())

(defmethod allocate-instance :before ((self c1) &rest ignore &key b)
  (declare (ignore ignore))
  (format t "Allocate-instance: b=~A.~%" b))

(defmethod shared-initialize :AFTER
	   ((self c1) slot-names &rest initargs &key b)
  (format t "Shared-initialize: b=~A.~%" b))

(make-instance 'c1 :b 10) -->
Error: Invalid initialization argument :B for class C1



;;; Yet the following works correctly:


(defclass c1()())

(defmethod allocate-instance :before ((self c1) &rest ignore &key b)
  (declare (ignore ignore))
  (format t "Allocate-instance: b=~A.~%" b))

(defmethod shared-initialize :AROUND
	   ((self c1) slot-names &rest initargs &key b)
  (format t "Shared-initialize: b=~A.~%" b)
  (call-next-method))

(make-instance 'c1 :b 10)
Shared-initialize around: b=10.

#<C1 34133731>



;;; Some related questions:
;;; 1.  Why is it necessary to define an allocate-instance method 
;;; just so that b can be an initialization argument?  The 
;;; documentation for method definitions which serve to declare 
;;; initialization arguments is confusing: "Making an instance of 
;;; a class: allocate-instance, initialize-instance, and shared-
;;; initialize.  Initialization arguments declared as valid by these 
;;; methods are valid when making an instance of a class."  Does this 
;;; mean that by making an instance of ONE of the three classes is 
;;; sufficient, or must an instance be made of each class?
;;; 2.  Why the allocate-instance :before method get invoked?  No
;;; "Allocate-instance: b=10." message was printed.

;;; Thanks, 
;;; Darrell Shane

;;; P.S. I am running Victoria Day PCL on Allegro CL 3.0.3.sun3.1