TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender: "Team Ada: Ada Programming Language Advocacy (83 & 95)" <[log in to unmask]>
Date: Fri, 3 Jun 2005 13:19:03 -0700
Reply-To: "Harbaugh, John S" <[log in to unmask]>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
From: "Harbaugh, John S" <[log in to unmask]>
Parts/Attachments: text/plain (86 lines)
By specifying default values in the type, you are declaring a definite
type.  You then have two options when declaring a variable of the type.
Either you let the defaults stand and thereby elaborate an unconstrained
object, or you override the defaults and elaborate a constrained object.
You can't elaborate an object that is half 'n half.  The results of
elaboration are very different for the two kinds of objects.

BTW, this thread is more appropriate to comp.lang.ada.  This mail list
is for Ada advocacy issues.

Thank you,

	- John

-----Original Message-----
From: Roger Racine [mailto:[log in to unmask]] 
Sent: Friday, June 03, 2005 1:06 PM
To: [log in to unmask]
Subject: Re: Disciminant question


I don't know the reason for the restriction, but could hazard a guess. 
What you are doing really is constraining a subtype.  Therefore, to make
sure you and all readers know what the constraints are, and don't
mistakenly think that only a subset of the discriminants are fixed for
the subtype, all discriminants must be given.  Again, this is only a
guess.  However, it has been said by many, many people that Ada is a
reader's language, not a writer's language.

Roger

On Fri, 2005-06-03 at 15:20, Chris Sparks wrote:
> The problem is that I rarely use discriminants.  It just seems silly 
> to
> me that given that there are initializers on the type definition
below, 
> the compiler can deduce what the other value is for MR2 and MR3.  Now
if 
> I didn't have initializers then that be a whole different matter.
> 
> C.
> 
> Roger Racine wrote:
> 
> >3.7.1(8) says "A discriminant_constraint shall provide exactly one 
> >value for each discriminant of the subtype being constrained."  While

> >one might think that one is constraining a discriminant, and thus 
> >only need to put in the subset of discriminants you want to 
> >constrain, the subtype is what is being constrained, and yours has 2 
> >discriminants, both of which need values.  That has been there since 
> >Ada 83.
> >
> >Roger Racine
> >
> >On Fri, 2005-06-03 at 12:24, Chris Sparks wrote:
> >  
> >
> >>Hello experts!
> >>
> >>I thought I understood discriminants, however, when I tried to 
> >>assign to
> >>MR2 and MR3 below, the compiler barked at me...
> >>
> >>----------------------------------------------------
> >>  type My_Record (Item : Integer := 1;
> >>                  Data : Integer := 2) is record
> >>    Stuff : Integer := Item * Data;
> >>  end record;
> >>
> >>  MR1 : My_Record;
> >>--MR2 : My_Record (Data => 3);
> >>--MR3 : My_Record (Item => 3);
> >>  MR4 : My_Record (Item => 10, Data => 11);
> >>----------------------------------------------------
> >>
> >>Can someone enlighten me on this?
> >>
> >>Chris Sparks
> >>    
> >>
> >
> >
> >  
> >

ATOM RSS1 RSS2