comp.lang.ada
 help / color / mirror / Atom feed
From: stt@henning.camb.inmet.com (Tucker Taft)
Subject: Re: access to subprogram disciminants
Date: 1996/04/26
Date: 1996-04-26T00:00:00+00:00	[thread overview]
Message-ID: <DqHBEC.63A.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 4lp3sc$glg@news1.delphi.com


tmoran@bix.com wrote:

: >What you are trying to accomplish can be done using normal record
: >*components*, initialized as a result of calling a function
: >or procedure.  In other OOP's, such a function would often be called
: >a "constructor," but in Ada, you can just use normal functions or
: >procedures as "constructors."

:   I had thought that 'constructor' in C++ was close to 'procedure
: initialize' for an Ada 95 Controlled type.  

Not really.  The procedure Initialize of a controlled type is
for *default* initialization, roughly equivalent to a parameterless
constructor for C++.  Constructor's with parameters are a better 
match for a parameterized Ada function the returns an initialized 
object, or a pointer to a newly allocated and initialized object.

: ... I also thought that the
: only parameters available to procedure 'initialize' were discriminants
: or other members of the record structure being initialized.  Further,
: the compiler will insist that values be supplied for (non-default
: valued) discriminants, whereas I can't get the compiler to enforce a
: requirement for *any* values for the rest of the record components.
: Am I mistaken?

If the type is private, then the user will have to call one of
your subprograms to initialize an object.  Such subprograms
can have parameters, with or without defaults.

If the type is also declared with "unknown" discriminants,
such as:
    type T(<>) is private;

then the user cannot declare a default-initialized object, but rather
must call one of your functions to specify the initial value.

: ...
:   I try to think of an Ada compiler not just as a tool to do scut work
: like converting code in an HLL to binary, but as a somewhat intelligent
: helper guiding me away from error.  Sort of like the difference between
: a rod and hangers keeping my clothes off the floor, vs a gentleman's
: valet suggesting that a particular tie might not be the best choice
: with a particular suit.  So I'm trying to arrange things so the
: language and compiler will be as helpful as possible.

I certainly sympathize with your goal of using the compiler to
help as much as possible.  However, I don't think discriminants
are the most appropriate way to accomplish this particular
kind of parameterization.  Functions with parameters are much
more flexible, and if used appropriately, more efficient.

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Cambridge, MA  USA




  parent reply	other threads:[~1996-04-26  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-26  0:00 access to subprogram disciminants tmoran
1996-04-26  0:00 ` Robert I. Eachus
1996-04-26  0:00 ` Tucker Taft [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-04-27  0:00 tmoran
1996-04-24  0:00 tmoran
1996-04-25  0:00 ` Tucker Taft
1996-04-23  0:00 tmoran
1996-04-24  0:00 ` Tucker Taft
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox