[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new new initialization protocol blues
- To: Gregor.pa@Xerox.COM
- Subject: Re: new new initialization protocol blues
- From: Danny Bobrow <Bobrow.pa@Xerox.COM>
- Date: 15 Jun 87 15:06 PDT
- Cc: Common-Lisp-Object-System@Sail.Stanford.edu, Bobrow.pa@Xerox.COM
- In-reply-to: Gregor.pa's message of 15 Jun 87 11:06 PDT
- Sender: Bobrow.pa@Xerox.COM
1) It is useful to be able to allocate storage for an instance without
having to evaluate all the initforms, for example, to build a
class-prototype without risking an error. Either this must be a
function that is called by allocate-instance, or it can be the job of
allocate instance. But in Gregor's message (and my earlier message) we
stated that
The method for allocate-instance on standard-class is
documented to allocate storage and evaluate and store all the
initforms.
A useful alternative may be to make the method for allocate-instance
only allocate storage for the instance. Then the primary method on
object for initialize-instance would be documented to evaluate and store
all the initforms.
2) Gregor's method not only exposes the proposed implementation of
initargs as methods, but suggests that the user must program using this
verbose style. Here is a useful macro, shown only in an example, that
would usually be used by users to specify how to handle inputs to
specify slot-values. The name of the macro can obviously be improved.
User-code:
(define-initialize-instance-after-method x-y-position (pos &key
start-the-engine)
((x :x number "a number") ;; initialize x a slot, checking its
type as a number
(y :second) ;; initialize y as a slot, using
keyword :second
z) ;; initialize z as a slot, using z as
the keyword
(when start-the-engine (fire-up pos))) ;; other user init code
----
Translation:
(defmethod initialize-instance :after
((pos x-y-position) &key start-the-engine
((:x #:g1) nil #:g2)
((:y #:g3) nil #:g4)
((z #:g5) nil #:g6)
&allow-other-keys)
(when #:g2
(check-type #:g1 number "a number")
(setf (slot-value pos 'x) #:g1))
(when #:g4
(setf (slot-value pos 'y) #:g3))
(when #:g6
(check-type #:g5 z-type) ;; this here if :type specified
in the class
(setf (slot-value pos 'z) #:g5))
;; Now comes the user-supplied body.
(when start-the-engine (fire-up pos)))