comp.lang.ada
 help / color / mirror / Atom feed
From: Jerry Petrey <jdpetreyNOSPAM@west.raytheon.com>
Subject: Re: use of attribute Pos
Date: 2000/10/11
Date: 2000-10-11T00:00:00+00:00	[thread overview]
Message-ID: <39E4ED9F.BC361EC0@west.raytheon.com> (raw)
In-Reply-To: 39E4A637.AE6EE630@cepsz.unizar.es



Alejandro Villanueva wrote:
> 
> Philippe Torres wrote:
> 
> > Hi, do you think the following behaviour is normal ?
> > -----
> > subtype Upper is character range 'A'..'Z' ;
> > begin
> > Put(Upper'Pos('A')) ;
> > -----
> > Output : 65
> >
> > I was expecting 0 since 'A' is the first element of Upper but i got
> > the ranking of 'A' in the Character type.
> >
> 
> Then you should have done this:
> -----
> type Upper is new Character range 'A' .. 'Z';
> begin
> Put (Upper'Pos ('A'));
> end;
> -----
> Output: 1


Actually this will also return the position in the base type Character
or 65.



> >
> > What's the point of defining constrained subtype if we can't use the
> >
> > attributes on it ? Or am i missing something ?
> >
> 
> If you use the subtype then the correct code would be:
> -----
> Put (Upper'Pos ('X') - Upper'Pos (Upper'First));
> 
> 

The above is the correct way to get what Philippe expected (with the X
being replaced by A)
since 'First does not apply to the base type.

Jerry
-- 
-----------------------------------------------------------------------------
-- Jerry Petrey                                                
-- Senior Principal Systems Engineer - Member Team Ada & Team Forth
-- Raytheon Missile Systems 
-- NOTE: please remove NOSPAM in email address to reply                  
-----------------------------------------------------------------------------




  parent reply	other threads:[~2000-10-11  0:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-11  0:00 use of attribute Pos Philippe Torres
2000-10-11  0:00 ` Jerry Petrey
2000-10-11  0:00   ` Ehud Lamm
2000-10-11  0:00 ` Pat Rogers
2000-10-12  0:00   ` Philippe Torres
2000-10-12  0:00     ` Robert A Duff
2000-10-12  0:00     ` Pat Rogers
2000-10-12  0:00       ` Philippe Torres
2000-10-12  0:00         ` mark.biggar
2000-10-12  0:00         ` Pat Rogers
2000-10-12  0:00           ` Tucker Taft
2000-10-12  0:00             ` Ehud Lamm
2000-10-12  0:00               ` Pat Rogers
2000-10-12  0:00               ` Philippe Torres
2000-10-12  0:00             ` Philippe Torres
2000-10-12  0:00               ` Ehud Lamm
     [not found] ` <39E4A637.AE6EE630@cepsz.unizar.es>
2000-10-11  0:00   ` Jerry Petrey [this message]
2000-10-14  3:32   ` Robert Dewar
2000-10-16  0:00     ` Alejandro Villanueva
2000-10-16  0:00       ` Robert Dewar
2000-10-18  0:00         ` Alejandro Villanueva
2000-10-16  0:00       ` Ken Garlington
2000-10-18  0:00         ` Alejandro Villanueva
replies disabled

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