comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: access to subprogram disciminants
Date: 1996/04/26
Date: 1996-04-26T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.96Apr26135437@spectre.mitre.org> (raw)
In-Reply-To: 4lp3sc$glg@news1.delphi.com


In article <4lp3sc$glg@news1.delphi.com> tmoran@bix.com writes:

 >    I had thought that 'constructor' in C++ was close to 'procedure
 > initialize' for an Ada 95 Controlled type.  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?

   Yes.  If a record component has a default initial value, you can
never create a record object where it's value is undefined.

   If you want to change a record discriminant, you are required to
assign an aggregate value so that any components which depend on the
discriminant have valid values.  This is nice for preserving the
principle above, but makes changing discriminants that do not
determine the other record components a lot more error prone.

   (Notice that it is possible in Ada to have discriminants on
subcomponents which are records that are not discriminants of the
parent type, and in fact the parent type may have no discriminants.
Take advantage of this to keep necessary discriminants as closely to
the components they control as you can.)

  > >Don't try to make all of these "parameters" into discriminants.
  > >Just declare them as components of the data type.  Then, a user would
  > >declare a simple "Frame_Window" or whatever, and initialize it from the
  > >result of a function call, or by a subsequent procedure call.
  >   But that function or procedure call might be left out, causing
  > a run time error.

   Yep, could be.  If you are that paranoid--and sometimes it is
correct to be--what I usually do is define a default initial value
that raises an exception.  Do it right, and your compiler will tell
you about it for every object which does not explicitly call an
constructor.

   type T is record...

     S: String(1..4) := (-3..0 => ' ');
   end record;

  >   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 try to do the same, but you have to be willing to listen to the
valet.  Get a compiler that issues good warning messages and never
turn them off.

    I had an example yesterday.  Recompiled some (GNAT compiled) code
that looked to be pure Ada 83 in VADS and got two warning messages.
Looked at the source and realized that Ada 83 did not allow sliding in
that context.  Modified the code and everything worked when finally
executed.  Much better than using the debugger.
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  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 [this message]
1996-04-26  0:00 ` Tucker Taft
  -- 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