comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Question about Ada and constant Arrays
Date: Tue, 11 Nov 2003 05:41:41 +0000
Date: 2003-11-11T05:41:41+00:00	[thread overview]
Message-ID: <bopsqv$1g9knj$1@ID-25716.news.uni-berlin.de> (raw)
In-Reply-To: <slrnbqvhev.97p.randhol+valid_for_reply_from_news@kiuk0156.chembio.ntnu.no>

Just for fun, a possible refinement might be something like this:

~~~

with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Array_Init_2 is

    package Boolean_IO is new Enumeration_IO(Boolean);
    use Boolean_IO;

    function "+" (Source: in String) return Unbounded_String
       renames To_Unbounded_String;

    procedure Put (Item: in Unbounded_String) is
    begin
       Put( To_String(Item) );
    end;

    type Test_Record is
       record
         Enabled : Boolean;
         Name    : Unbounded_String;
         Value   : Integer;
       end record;

    type Test_Array is array (Positive range <>) of Test_Record;

    My_Array : constant Test_Array :=
       (1 => (True,  +"Test1",            1),
        2 => (False, +"Test2",            2),
        3 => (False, +"Test3",            4),
        4 => (False, +"Test4",            8),
        5 => (True,  +"Test5 (whoopee)", 16),
        6 => (False, +"Test *** 6 ***",  17));
begin

    --  Printing the values to show that it is correct.

    for i in My_Array'Range loop
       Put(i);
       Put(" => ");
       Put(My_Array(i).Enabled);
       Put(", ");
       Put(My_Array(i).Name);
       Put(", ");
       Put(My_Array(i).Value);
       New_Line;
    end loop;

end Array_Init_2;

~~~

I haven't tested this code.

-- 
Nick Roberts




  parent reply	other threads:[~2003-11-11  5:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-10 16:49 Question about Ada and constant Arrays Stephane Richard
2003-11-10 17:07 ` Preben Randhol
2003-11-10 17:10   ` Stephane Richard
2003-11-10 17:13     ` Preben Randhol
2003-11-10 17:11   ` Preben Randhol
2003-11-11  5:41   ` Nick Roberts [this message]
2003-11-11  9:34 ` Lutz Donnerhacke
replies disabled

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