comp.lang.ada
 help / color / mirror / Atom feed
* type declaration problem(beginner)
@ 1997-02-26  0:00 dawkins
  1997-03-02  0:00 ` johnherro
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: dawkins @ 1997-02-26  0:00 UTC (permalink / raw)



 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.

Any help from someone who may know would be helpful. I'm just learning ada 
and having a hard time following the book. Oh yea, anyone know of any good 
books on ada.


Scott Dawkins
dawkins@ssdd.nrl.navy.mil




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: type declaration problem(beginner)
  1997-02-26  0:00 type declaration problem(beginner) dawkins
@ 1997-03-02  0:00 ` johnherro
  1997-03-02  0:00   ` Robert Dewar
  1997-03-03  0:00 ` johnherro
  1997-03-05  0:00 ` David Wheeler
  2 siblings, 1 reply; 5+ messages in thread
From: johnherro @ 1997-03-02  0:00 UTC (permalink / raw)



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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: type declaration problem(beginner)
  1997-03-02  0:00 ` johnherro
@ 1997-03-02  0:00   ` Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1997-03-02  0:00 UTC (permalink / raw)



John Herro said

<<The second example is written the way it is because it's always a good idea to q
ualify the aggregate when "others" follows named notation.  This was more import
ant 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.
>>

No, that is superstition, there is no point in putting in unnecessary
qualifications, and this one is unnecessary. It may be a good idea if
you do not understand the rules, but in practice in Ada 95, you can
indeed avoid junk qualifications in cases like this.

It is true that in Ada 83, the qualification was needed in some cases where
it appears unnecessary, so many people adopt the style of using it all the
time in Ada 83, but this is a bit of Ada 83 superstition that need not be
carried forward to Ada 95. Write the qualification only if it helps
readability (in the quoted case, it clearly does NOT do so)





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: type declaration problem(beginner)
  1997-02-26  0:00 type declaration problem(beginner) dawkins
  1997-03-02  0:00 ` johnherro
@ 1997-03-03  0:00 ` johnherro
  1997-03-05  0:00 ` David Wheeler
  2 siblings, 0 replies; 5+ messages in thread
From: johnherro @ 1997-03-03  0:00 UTC (permalink / raw)



I wrote:
>> type Set_Type is array(Month) of Boolean; ...
>> Short_Months : Set_Type := Set_Type'(Feb|Apr|Jun|Sep|Nov => True,
others => False);
Robert Dewar wrote:
> there is no point in putting in unnecessary
> qualifications, and this one is unnecessary...
> Write the qualification only if it helps readability
> (in the quoted case, it clearly does NOT do so)
     Robert is right, of course.  The rules about when qualification was necessary when "others" followed named notation were quite complicated in Ada 83, and as I teacher I recommended that students always qualify the aggregate in such cases, rather than learn the complex rules.  For example, after a "return" statement in a function, such qualification was unnecessary, but in the above example, the qualification *was* necessary in Ada 83.  In Ada 95 the rules regarding this are simpler.  Assuming the original poster, Scott Dawkins, is using an Ada 95 compiler (and that's the assumption here in comp.lang.ada unless the poster says otherwise), the qualification, although accepted by the compiler, is unnecessary.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: type declaration problem(beginner)
  1997-02-26  0:00 type declaration problem(beginner) dawkins
  1997-03-02  0:00 ` johnherro
  1997-03-03  0:00 ` johnherro
@ 1997-03-05  0:00 ` David Wheeler
  2 siblings, 0 replies; 5+ messages in thread
From: David Wheeler @ 1997-03-05  0:00 UTC (permalink / raw)



dawkins@whisky.nrl.navy.mil (Scott Dawkins) wrote:
:  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.

: Any help from someone who may know would be helpful. I'm just learning ada 
: and having a hard time following the book. Oh yea, anyone know of any good 
: books on ada.

Use:
 type Set_Type is array(Month) of Boolean;

For good books, try out my "Lovelace" Ada95 tutorial.
It's available on-line at:
   http://www.adahome.com/Tutorials/Lovelace/lovelace.htm
By the end of the March 1997 it should be available as a book.


--- David A. Wheeler
    dwheeler@ida.org





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1997-03-05  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-26  0:00 type declaration problem(beginner) dawkins
1997-03-02  0:00 ` johnherro
1997-03-02  0:00   ` Robert Dewar
1997-03-03  0:00 ` johnherro
1997-03-05  0:00 ` David Wheeler

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