comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com
Subject: Re: type declaration problem(beginner)
Date: 1997/03/02
Date: 1997-03-02T00:00:00+00:00	[thread overview]
Message-ID: <19970302214000.QAA14807@ladder02.news.aol.com> (raw)
In-Reply-To: 1997Feb26.120011.27@whisky


Idawkins@whisky.nrl.navy.mil writes:
> I have a type declarations, example:
>		type Month is (Jan, Feb, etc...)
> I want to write another declaration for a array of
> boolean values, Set_type.  Use the type Month
> for the indices into the array.

   type Set_Type is array(Month) of Boolean;

Then you could declare, for example,

Null_Set : constant Set_Type(others => false);

or

Short_Months : Set_Type := Set_Type'(Feb|Apr|Jun|Sep|Nov => True, others => False);

The second example is written the way it is because it's always a good idea to qualify the aggregate when "others" follows named notation.  This was more important in Ada 83 than it is in Ada 95, but it's still a good idea.  The "Set_Type'" before the "(" is called qualifying the aggregate.

When you have two objects that are one-dimensional arrays of Boolean, such as Set_Type, you can "and" and "or" the entire arrays.  You don't have to set up a loop and "and" or "or" one element at a time.  "And" corresponds to set intersection, and "or" is set union.  Thus,

A, B, C : Set_Type;
...
A := B or C;

sets A to B union C.

At the Web and FTP sites below my signature, you can download my shareware Ada Tutor program, and there's a coupon there for a good Ada textbook; you send the coupon directly to the publisher.  I hope this helps.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor





  reply	other threads:[~1997-03-02  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-26  0:00 type declaration problem(beginner) dawkins
1997-03-02  0:00 ` johnherro [this message]
1997-03-02  0:00   ` Robert Dewar
1997-03-03  0:00 ` johnherro
1997-03-05  0:00 ` David Wheeler
replies disabled

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