comp.lang.ada
 help / color / mirror / Atom feed
* how to print position number of an enumeration variable?
@ 2001-09-30  1:09 mike
  2001-09-30  2:31 ` DuckE
  0 siblings, 1 reply; 8+ messages in thread
From: mike @ 2001-09-30  1:09 UTC (permalink / raw)


hello,

suppose I have a variable of some enumeration type, and I want to
print or find the position number in the enumeration type that this
variable holds. How can do that?

for example:

-----------
with Ada.Text_Io; use Ada.Text_Io;

procedure Enum is
  type Day_type is (Monday, Tuesday, Wednesday, Thursday, 
                    Friday, Saturday, Sunday);

  Day Day_Type := Monday;

begin

   Put_Line("the position number of first enumeration elemenet is " & 
             Day_type'Image( ???? ) );

end Enum;

---------------

I know that the first enumeration literal will have a position of 0. But
I just wanted to see if one can print this value. I looked at the attributes
of scalar data types, and do not see something like S'pos ?

thanks,
mike




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

* Re: how to print position number of an enumeration variable?
  2001-09-30  1:09 how to print position number of an enumeration variable? mike
@ 2001-09-30  2:31 ` DuckE
  2001-09-30  5:37   ` mike
  0 siblings, 1 reply; 8+ messages in thread
From: DuckE @ 2001-09-30  2:31 UTC (permalink / raw)


Perhaps:
  Put_Line( "the position number of the first enumeration element is " &
                  Integer'Image( Day_Type'Pos( Day_Type'First ) ) );

SteveD

"mike@athome" <mike_member@newsguy.com> wrote in message
news:9p5rd30202n@drn.newsguy.com...
> hello,
>
> suppose I have a variable of some enumeration type, and I want to
> print or find the position number in the enumeration type that this
> variable holds. How can do that?
>
> for example:
>
> -----------
> with Ada.Text_Io; use Ada.Text_Io;
>
> procedure Enum is
>   type Day_type is (Monday, Tuesday, Wednesday, Thursday,
>                     Friday, Saturday, Sunday);
>
>   Day Day_Type := Monday;
>
> begin
>
>    Put_Line("the position number of first enumeration elemenet is " &
>              Day_type'Image( ???? ) );
>
> end Enum;
>
> ---------------
>
> I know that the first enumeration literal will have a position of 0. But
> I just wanted to see if one can print this value. I looked at the
attributes
> of scalar data types, and do not see something like S'pos ?
>
> thanks,
> mike
>





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

* Re: how to print position number of an enumeration variable?
  2001-09-30  2:31 ` DuckE
@ 2001-09-30  5:37   ` mike
  2001-09-30  6:27     ` James Rogers
  2001-09-30 12:50     ` Robert Dewar
  0 siblings, 2 replies; 8+ messages in thread
From: mike @ 2001-09-30  5:37 UTC (permalink / raw)



In article <3uvt7.55862$QK.36794657@news1.sttln1.wa.home.com>, "DuckE" says...
>
>Perhaps:
>  Put_Line( "the position number of the first enumeration element is " &
>                  Integer'Image( Day_Type'Pos( Day_Type'First ) ) );
>
>SteveD
>
 
but 'pos is not listed as an attribute. I am looking at page 34-36 of the RM,
and I do not see such attribute for scalar types (that is why I asked), and enum
is scalar type.

strange. But thanks!

mike




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

* Re: how to print position number of an enumeration variable?
  2001-09-30  5:37   ` mike
@ 2001-09-30  6:27     ` James Rogers
  2001-09-30 12:52       ` Robert Dewar
  2001-10-02 17:49       ` Randy Brukardt
  2001-09-30 12:50     ` Robert Dewar
  1 sibling, 2 replies; 8+ messages in thread
From: James Rogers @ 2001-09-30  6:27 UTC (permalink / raw)


"mike@nospam" wrote:
> 
> but 'pos is not listed as an attribute. I am looking at page 34-36 of the RM,
> and I do not see such attribute for scalar types (that is why I asked), and enum
> is scalar type.
> 
> strange. But thanks!


Look again. This time look at page 474 of the RM, in the summary of
Language Defined Attributes.

You will find the following:

S'Pos  For every discrete subtype S:
       
       S'Pos denotes a function with the following specification:
           function S'Pos(Arg : S'Base) return universal_integer

       This function returns the position number of the value Arg,
       as a value of type universal_integer. 

All enumeration types are discrete types.

Jim Rogers
Colorado Springs, Colorado USA



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

* Re: how to print position number of an enumeration variable?
  2001-09-30  5:37   ` mike
  2001-09-30  6:27     ` James Rogers
@ 2001-09-30 12:50     ` Robert Dewar
  2001-09-30 13:53       ` David Botton
  1 sibling, 1 reply; 8+ messages in thread
From: Robert Dewar @ 2001-09-30 12:50 UTC (permalink / raw)


mike@nospam <mike_member@newsguy.com> wrote in message news:<9p6b3m02v4v@drn.newsguy.com>...
> In article <3uvt7.55862$QK.36794657@news1.sttln1.wa.home.com>, "DuckE" says...
> >
> >Perhaps:
> >  Put_Line( "the position number of the first enumeration element is " &
> >                  Integer'Image( Day_Type'Pos( Day_Type'First ) ) );
> >
> >SteveD
> >
>  
> but 'pos is not listed as an attribute. I am looking at page 34-36 of the RM,
> and I do not see such attribute for scalar types (that is why I asked), and enum
> is scalar type.
> 
> strange. But thanks!
> 
> mike

Yes, but 'Pos is not defined for all scalar types, so of
course you do not see it there, instead look for attributes
of discrete types and you will find it in RM 3.5.5.

But a little higher level advice, you definitely need to
improve your skills in finding things in the RM. Two
suggestions:

1. If you have a paper copy (or an electronic copy), use
the index. That is what it is there for! The index is quite
complete, and there is an entry for Pos that points to
3.5.5.

2. Get an electronic copy. There are HTML versions around,
but I prefer a straight ASCII version easily searched in
any editor, and then just search for Pos.



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

* Re: how to print position number of an enumeration variable?
  2001-09-30  6:27     ` James Rogers
@ 2001-09-30 12:52       ` Robert Dewar
  2001-10-02 17:49       ` Randy Brukardt
  1 sibling, 0 replies; 8+ messages in thread
From: Robert Dewar @ 2001-09-30 12:52 UTC (permalink / raw)


James Rogers <jimmaureenrogers@worldnet.att.net> wrote in message news:<3BB6BB75.D88EECE3@worldnet.att.net>...

> Look again. This time look at page 474 of the RM, in the 
> summary of Language Defined Attributes.
> 
Note that although this is a useful reference, this is not
part of the RM, i.e. it is not part of the normative part
of the RM, Annex K is merely informative. The proper
reference for the 'Pos attribute is 3.5.5 (there is nothing
in Annex K that is not elsewhere, Annex K is simply a useful
collecting of information available elsewhere -
actually it was my suggestion to add Annex K to the
standard :-)



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

* Re: how to print position number of an enumeration variable?
  2001-09-30 12:50     ` Robert Dewar
@ 2001-09-30 13:53       ` David Botton
  0 siblings, 0 replies; 8+ messages in thread
From: David Botton @ 2001-09-30 13:53 UTC (permalink / raw)
  To: comp.lang.ada

Another excellent version of the RM is the Window HTML Help version included
in AdaGIDE. It allows searching and then some.

David Botton

----- Original Message -----
From: "Robert Dewar" <dewar@gnat.com>
> 2. Get an electronic copy. There are HTML versions around,
> but I prefer a straight ASCII version easily searched in
> any editor, and then just search for Pos.





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

* Re: how to print position number of an enumeration variable?
  2001-09-30  6:27     ` James Rogers
  2001-09-30 12:52       ` Robert Dewar
@ 2001-10-02 17:49       ` Randy Brukardt
  1 sibling, 0 replies; 8+ messages in thread
From: Randy Brukardt @ 2001-10-02 17:49 UTC (permalink / raw)


"mike@nospam" wrote:
>
> but 'pos is not listed as an attribute. I am looking at page 34-36 of
the RM,
> and I do not see such attribute for scalar types (that is why I
asked), and enum
> is scalar type.
>
> strange. But thanks!


'Pos isn't defined for scalar types; it's only defined for discrete
types. (That is, it isn't defined for floats and fixed point types).
Look in 3.5.5 to find the normative definition of 'Pos.

            Randy.






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

end of thread, other threads:[~2001-10-02 17:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-30  1:09 how to print position number of an enumeration variable? mike
2001-09-30  2:31 ` DuckE
2001-09-30  5:37   ` mike
2001-09-30  6:27     ` James Rogers
2001-09-30 12:52       ` Robert Dewar
2001-10-02 17:49       ` Randy Brukardt
2001-09-30 12:50     ` Robert Dewar
2001-09-30 13:53       ` David Botton

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