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

Re: Constructors

     Date: 21 Oct 87 16:39 PDT
     From: Danny Bobrow <Bobrow.pa@xerox.com>
     Subject: Re: Constructors 
      jak:      I don't think the difference between;
              	(make-foo :name 'bar :number-of-widgits 50)
              	(make-instance 'foo :name 'bar :number-of-widgits 50)
              is sufficiently large to constitute a useful addition in
     pd  The difference is the same as between
         (send object :do-this ) and (do-this object).
     I don't understand the analogy at all.

If the interface to my program is a bunch of SEND messages, I expose (to
my user)the fact that I am using object programming.  Sometimes this is
fine, sometimes I want to be more abstract.  Generic functions give me
this abstraction.  If the consing interface of my program is a bunch of
MAKE-INSTANCE, I expose the fact that I am using object programming.  In
this sense, a constructor function gives me an abstraction for consing,
like generic functions give me the abstraction for programming.
     pd   You do that by adding the following option in the defclass:
          (:CONSTRUCTOR make-bar-foo (number-of-widgits &aux (name 'bar)))
         This option is textually close to the initargs declaration,
         which is another advantage over a separate constructor function.
     1) How does the &aux get added to the argument list of a constructor?
     How does this do what jak asked for?

I am including the relevant part from Moon's proposal:
Each parameter supplies the value of
one initarg, determined by the following rules:
 - If a parameter variable name is EQ to an initarg name, the parameter 
   supplies the value of that initarg.
 - If a parameter variable name is not EQ to any initarg name, but the symbol
   in the keyword package with the same name as the parameter variable
   name is EQ to an initarg name, the parameter supplies the value of that
 - If neither rule succeeds, signal an error.
The second rule exists because initarg names are often keyword symbols, which
are not valid as variable names.
-constructor-lambda-list- allows all of the standard lambda-list features that
DEFUN allows. 

     2) This option is not textually close to any inherited initarg
     declarations.  The fact that it is close to some and not all has large
     confusion potential.

It is not more confusing that the :DEFAULT-INITARGS option, and
certainly less than a separate constructor definition.
         On any architecture, if you implement MAKE-INSTANCE by
         interpreting the various data structures (initargs list, default
         initargs), it is going to be costly.  You will need a mechanism to
         generate some specialized code reflecting the interpretation for a
         particular class.  
     This is clearly a good thing.
     The question it is better to focus it on calls to make-instance, or is
     it better  to combine this optimization with an automatic function
     generation facility, with other features?  The former seems like the
     "general mechanism" to me (pd says "I think it is better to
     agree one a general mechanism.")

I see moon's proposal being a good combination of desirables features.