From: Georg Bauhaus <see.reply.to@maps.futureapps.de>
Subject: Re: Array Syntax
Date: Fri, 29 Feb 2008 18:16:17 +0100
Date: 2008-02-29T18:16:17+01:00 [thread overview]
Message-ID: <47c83de1$0$11006$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <f62dad2b-1e64-4289-bd05-3ce7db98ffee@k2g2000hse.googlegroups.com>
ma740988@gmail.com wrote:
> Trying to garner a feel for Ada - while perusing texts - and I'm
> having slight difficulties understanding array syntax.
>
>
> Max_Num : constant := 6;
>
> type Pixel_Data is
> record
> Num_Of_Values : Int32;
> Is_Valid_Data : Boolean;
> end record;
>
> type Pixel_Number is Int16 range 1 .. Max_Num ;
> type Pixel_Data_Array is array
> ( Pixel_Number range 1 .. Max_Num )
> of Pixel_Data;
>
> Pixel_Data_Array is an array 6 deep of composite type Pixel Data. So
> far so good?
Yes, though either Pixel_Number should be a "new Int16"
or else a subtype of Int16. Below, you'll find an aggregate
object of your anonymous array Buffer_Pixel_Data.
The numbers in the leftmost column are index values of
this type's index.
D1: constant Pixel_Data :=
(Num_Of_Values => 42, Is_Valid_Data => true);
D2: constant Pixel_Data :=
(Num_Of_Values => -666, Is_Valid_Data => false);
begin
Buffer_Pixel_Data :=
-- the first component of Buffer_Pixel_Data
-- is an array of six, assigned one by one:
(1 => Pixel_Data_Array'(1 => (0, True),
2 => (-1, false),
3 => (0, False),
4 => D2, 5 => D1,
6 => Pixel_Data'(D2)),
-- the components of the array are records of type Pixel_Data
-- the last one, at index 6, emphasizes
-- using range 1 .. Max_Num for collectively setting values
2 | 4 => Pixel_Data_Array'(1 .. Max_Num => D2),
-- explicitly mention the respective index type (as per Ludovic's
-- remarks). The type of 6 is inferred by the compiler
Int32'(6) => Pixel_Data_Array'(Pixel_Number'(1) .. 6 => D2),
-- at index positions 3, 5, and 7 put an array with all
-- components set to record value (1, True)
3 | 5 | 7 => Pixel_Data_Array'(others => (1, True)),
-- you can indicate the range of index values by not using
-- single index values, but the 'Range of the index type,
8 .. 9 => Pixel_Data_Array'(Pixel_Number'Range => D2),
-- but it is sufficient to just name the index type
10 .. Frames_in_Buffer => Pixel_Data_Array'(Pixel_Number => D1));
-- the latter two work because of a coincidence:
-- type Pixel_Number is new Int16 range 1 .. Max_Num ;
-- and
-- type Pixel_Data_Array is array
-- ( Pixel_Number range 1 .. Max_Num ) ... have the same range
constraint
end News6;
next prev parent reply other threads:[~2008-02-29 17:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-29 15:19 Array Syntax ma740988
2008-02-29 16:01 ` Ludovic Brenta
2008-02-29 17:16 ` Georg Bauhaus [this message]
2008-02-29 17:48 ` Dmitry A. Kazakov
2008-02-29 17:50 ` Jeffrey R. Carter
2008-03-04 16:18 ` ma740988
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox