comp.lang.ada
 help / color / mirror / Atom feed
* strings and multidimensional arrays
@ 2003-10-12  4:05 Andrew
  2003-10-12  5:24 ` Andrew
  2003-10-13 13:59 ` Rodrigo Garcia
  0 siblings, 2 replies; 15+ messages in thread
From: Andrew @ 2003-10-12  4:05 UTC (permalink / raw)


Is this possible:
Can I create a multi-dimensional array.. and then at say row (4) , 
column (5)  have an entirely new string built?

basically having a string within a multi-dimensional array...
?
and if this is possible what would be a good place to look for ideas on 
how to do this?
thanks
Andrew




^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: strings and multidimensional arrays
@ 2003-10-14  6:24 christoph.grein
  0 siblings, 0 replies; 15+ messages in thread
From: christoph.grein @ 2003-10-14  6:24 UTC (permalink / raw)
  To: comp.lang.ada

> Very interesting.  I see no problem with your package as written, in
> fact I see no problem created objects of the array type.  (The
> discriminants will all be assigned the default value One.)  But I
> expected that a record assignment to an element that changed the
> discriminant would raise Constraint_Error.  However, when I created an
> instance of your array type and assigned to it this is what I got (from 
> GNAT):
> 
> ----------------------------------------------------------------------
> with Ada.Text_IO; use Ada.Text_IO;
> with Ada.Float_Text_IO;
> procedure Disc_Test is
> 
>    package Test_Unconstrained_Record_Array is
>      type Disc is (One, Two, Five);
> 
>      type Unconstrained_Record (D : Disc := One) is record
>        case D is
>        when One =>
>           I : Integer;
>        when Two =>
>           C : Character;
>        when Five =>
>           F : Float;
>        end case;
>      end record;
> 
>      type Thing is array (Positive range <>, Positive range <>) of
>                  Unconstrained_Record;
> 
>    end Test_Unconstrained_Record_Array;
> 
>    package TURA renames Test_Unconstrained_Record_Array;
>    package TURA_IO is new Ada.Text_IO.Enumeration_IO(TURA.Disc);
> 
>    TT: TURA.Thing(1..5, 1..5);
> 
> begin
> 
>    TT(1,1) := (TURA.One, 1);
>    TT(2,2) := (TURA.Two, '2');
>    TT(5,5) := (TURA.Five, 5.0);
>    for I in 1..5 loop
>      Put(" TT(" & Integer'Image(I)(2) & ',' & Integer'Image(I)(2) & ") 
> is ");
>      Put("( D => "); TURA_IO.Put(TT(I,I).D);
>      case TT(I,I).D is
>        when TURA.One =>
>          Put(" I =>"); Put(Integer'Image(TT(I,I).I));
>        when TURA.Two =>
>          Put(" C =>"); Put(Character'Image(TT(I,I).C));
>        when TURA.Five =>
>          Put(" I =>"); Ada.Float_Text_IO.Put(TT(I,I).F,2,1,0);
>      end case;
>      Put_Line(").");
>    end loop;
> end Disc_Test;
> 
> -----------------------------------------------------------------------------
> 
> E:\Ada\Test>disc_test
> disc_test
>   TT(1,1) is ( D => ONE I => 1).
>   TT(2,2) is ( D => TWO C =>'2').
>   TT(3,3) is ( D => ONE I => 2013340188).
>   TT(4,4) is ( D => ONE I => 38010744).
>   TT(5,5) is ( D => FIVE I => 5.0).
> 
> I'm not going to assert that this is wrong. That would be for the ARG as
> a whole to do.  The key paragraphs of the standard are 3.6(14): "An 
> array_type_definition defines an array type and its first subtype.
> For each object of this array type, the number of indices, the type and
> position of each index, and the subtype of the components are as in the
> type definition[; the values of the lower and upper bounds for each
> index belong to the corresponding index subtype of its type, except for
> null arrays (see 3.6.1)]."  This is the paragraph that implicitly sets 
> the discriminants for uninitialized components.
> 
> And 3.6(11): "Within the definition of a nonlimited composite type (or a 
> limited composite type that later in its immediate scope becomes 
> nonlimited -- see 7.3.1 and 7.5), if a component_definition contains the 
> reserved word aliased and the type of the component is discriminated, 
> then the nominal subtype of the component shall be constrained."
> 
> The first quote implies that the subtype of the components can't be 
> changed, the second implies they can be unless the components are 
> declared as aliased.  (Adding the wrapper type allows you to declare the 
> components aliased.)  I'll wait to see what Bob Duff, Randy, and 
> possibly Tucker have to say.  Certainly this is not documented as a 
> change from Ada 83 in the AARM.  But even if it wasn't intended as 
> legal, it is a nice feature. ;-)

I think here the language lawyer is in error (even gurus aren't infallible ;-). 
This has already been legal in 
Ada83, a wrapper was never needed.



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

end of thread, other threads:[~2003-10-14 15:29 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-12  4:05 strings and multidimensional arrays Andrew
2003-10-12  5:24 ` Andrew
2003-10-12  6:27   ` tmoran
2003-10-12 14:16   ` Robert I. Eachus
2003-10-12 19:34     ` Jeffrey Carter
2003-10-13  0:02       ` Robert I. Eachus
2003-10-13  3:14         ` Jeffrey Carter
2003-10-13 17:05           ` Robert I. Eachus
2003-10-13 18:49             ` Martin Dowie
2003-10-13 21:47               ` Mark Lorenzen
2003-10-14  1:10             ` Jeffrey Carter
2003-10-14 15:29               ` Robert I. Eachus
2003-10-12 21:01     ` Andrew
2003-10-13 13:59 ` Rodrigo Garcia
  -- strict thread matches above, loose matches on Subject: below --
2003-10-14  6:24 christoph.grein

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