[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Questions on new CLOS document
- To: Scott E. Fahlman <Fahlman@C.CS.CMU.EDU>
- Subject: Questions on new CLOS document
- From: Gregor.pa@Xerox.COM
- Date: Sun, 14 Feb 88 16:04 PST
- Cc: CommonLoops.pa@Xerox.COM
- Fcc: BD:>Gregor>mail>outgoing-mail-1.text
- In-reply-to: <FAHLMAN.12374546454.BABYL@C.CS.CMU.EDU>
- Line-fold: no
Date: Sat, 13 Feb 88 22:33 EST
From: "Scott E. Fahlman" <Fahlman@C.CS.CMU.EDU>
[ This may not be the right place for queries about the draft CLOS spec
itself. Is there a better place to send these? I think that the answer
to some of these questions might be of interest to most current PCL
users. ]
Probably messages like this one should be sent to both the CommonLoops
list and the common-lisp-object-system@sail.stanford.edu. That way they
will be seen by all the CLOS designers and also by all the current PCL
users.
It appears that one can no longer do something like
(defclass foo ()
(a b))
(setq inst (make-instance 'foo :a 1 :b 2))
As I read the document, you have to explicitly supply :a and :b as
:initarg options in the defclass call if you want to be able to
initialize them in Make-Instance. Is that true? I can see the reason
for wanting the general initarg mechanism, but was it really necessary
to flush the convenient default?
This was done for the same reason there isn't a simple option to
generate accessors for all the slots. We didn't want to endorse a
particular convention for naming initargs. We felt that there were good
reasons why a programmer might want to have all their initargs be
symbols in the keyword package and also good reasons why they would want
them to be symbols in some other package. So it seemed best to require
that people specify the initargs one at a time.
I don't have it, but several weeks ago Dave Moon sent a message to the
CLX mailing list which I remember as providing an excellent description
of the motivation for this decision.
Second question:
I notice that in the new With-Slots call, there is no longer any way to
explicitly specify the class to which the instance in question belongs.
I note also that With-Slots now is defined as expanding into a bunch of
Slot-Value calls. Presumably if you use this form within a method that
specifies the class of the instance, you can reasonably expect these
Slot-Value calls to produce efficient inline access forms. But what
about the case where With-Slots is used somewhere other than in a
method? Will those access forms be grossly inefficient because they had
to be compiled with no knowledge of the class to which the instance
belongs? Is there some way for the user to declare this, or do you just
have to avoid with-slots when you're not inside a method?
The type declaration can be used to specify the class of (the value of)
a variable. Implementations can use these type declarations to optimize
these slot-value forms.
(let ((pos (get-the-pos)))
(declare (type position pos))
(with-slots (x y) pos
(list x y)))
CLOS provides greater latitude for optimizing calls to slot-value which
appear inside of method bodies than it does in other contexts, but I
think it is still possible to get high performance slot-value in a
context where the class is declared with a type declaration. My
expectation is that there would be some overhead on the first call to
slot-value which would then not be incurred on subsequent calls. So the
code fragment above might not average out so well, but if it had more
calls to slot-value in it, the average performance of the calls would
approach the best time provided by the given CLOS implementation.
The current version of PCL only optimizes calls to slot-value which
appear in method bodies. A future version may optimize other calls to
slot-value, but it is not clear it will do so in all of its ports.
-------