[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
> Most programmers will want to name their constructors in a way which
> is reflective of their function, to construct a particular class. Thus,
> if they change the class name, it would make sense to change the
> constructor name, so that the name continues to reflect the function.
> Whether they change a constructor function name or a class name in
> a MAKE-INSTANCE form makes little difference. Thus, for the price of
> yet another DEFCLASS construct, you get very little in the way of
> additional abstraction. And, as has been argued, programmers who
> want to do this will do it anyway. Most programmers are going to
> want to do things like:
> (defun make-bar-foo (widgits)
> (make-instance 'foo :name 'bar :number-of-widgits widgits))
> You do that by adding the following option in the defclass:
> (:CONSTRUCTOR make-bar-foo (number-of-widgits &aux (name 'bar)))
I guess this example sums up the problem I have with the constructors
proposal as it stands. The semantics outlined in the original basenote
seem good, I guess I just don't like the syntax.
As a further example, consider if the programmer wants both a constructor
to make an instance with WIDGITS given and one with the name. Then the
DEFCLASS form would have to contain another :CONSTRUCTOR, with another
lambda list. One of the reasons I like Lisp over other languages is
because of the syntactic simplicity. The DEFCLASS form is already
syntatically fairly complex.
> This option is textually close to the initargs declaration, which is
> another advantage over a separate constructor function.
One could make this same argument about slot names and methods, that
the method definitions should be textually close to the slot definitions.
In fact, some Smalltalk programmers have made this argument, since this
is so in Smalltalk.
What would be the problem with having a seperate form to declare
constructors (other than incompatibility with DEFSTRUCT)? This could
even give the programmer more flexibility during the debugging phase,
since a programmer could more easily trace the "interpreted" or long
form of instantiation while debugging, then add the constructor afterwards,
during optimization, without having to modify the DEFCLASS form. While
debugging, a simple function could serve as the abstract interface.