comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Half Constrained Array Types and Slices
Date: Thu, 2 Mar 2006 20:37:00 +0100
Date: 2006-03-02T20:37:00+01:00	[thread overview]
Message-ID: <11dl471sl1hwr$.112glc09jnpkb.dlg@40tude.net> (raw)
In-Reply-To: 1141313690.19791.1.camel@sonnenregen

On Thu, 02 Mar 2006 16:34:50 +0100, Georg Bauhaus wrote:

> On Thu, 2006-03-02 at 09:34 +0100, Dmitry A. Kazakov wrote:
>> On Thu, 02 Mar 2006 05:00:06 GMT, Jeffrey R. Carter wrote:
> 
>>> type String (Length : Natural) is array (1 .. Length) of Character;
>> 
>> Not only this. Discriminants for arrays would also allow nice things like:
>> 
>> type Table (Element_Size : Natural) is
>>    array (...) of String (1..Element_Size);
> 
> If you didn't dislike generics that much,
>
> generic
>    Element_Size: NATURAL;
> package String_Tables is
> 
>    subtype SIZED_STRING is STRING(1.. Element_Size);
> 
>    type TABLE is array(POSITIVE range <>) of SIZED_STRING;
> 
> end String_Tables;

Nope:

type Table (Element_Size : Natural) is
   array (...) of String (1..Element_Size);

function Read_From_File (File : File_Type) return Table;
function Write_To_File (File : File_Type; X : Table);
   -- Notice indefinite formal parameters and results are OK

subtype Punched_Cards is Table (80);
   -- Subtypes are OK

This is why I dislike generics. Each instance of String_Tables produces an
independent type. So there is no either named type or objects of the class
TABLE.

----
Note that this problem is known since Pascal. Strings in original Pascal
were of different types, when they had different lengths. Ada 83 introduced
the idea of unconstrained types to handle this nuisance. So different sizes
induced subtypes rather than types. Though the latter were also possible
using "type is new."

Generics is not Ada! (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2006-03-02 19:37 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-02  5:00 Half Constrained Array Types and Slices Jeffrey R. Carter
2006-03-02  8:34 ` Dmitry A. Kazakov
2006-03-02 15:34   ` Georg Bauhaus
2006-03-02 19:37     ` Dmitry A. Kazakov [this message]
2006-03-02 20:06   ` Jeffrey R. Carter
2006-03-02 20:37     ` Dmitry A. Kazakov
2006-03-02 21:01     ` Robert A Duff
2006-03-02 20:40   ` Robert A Duff
2006-03-02 14:32 ` Larry Kilgallen
2006-03-02 20:08   ` Jeffrey R. Carter
2006-03-02 20:48   ` Robert A Duff
2006-03-06  2:16     ` Larry Kilgallen
2006-03-06 18:50       ` Martin Krischik
2006-03-02 20:38 ` Robert A Duff
2006-03-03  5:15   ` Jeffrey R. Carter
2006-03-03  8:57     ` Dmitry A. Kazakov
2006-03-03 23:41     ` Robert A Duff
2006-03-06 17:50       ` Jeff Carter
2006-03-06 18:31         ` Dmitry A. Kazakov
2006-03-07 19:02           ` Jeff Carter
2006-03-08 14:29             ` Dmitry A. Kazakov
2006-03-09 22:44               ` Robert A Duff
2006-03-10  8:46                 ` Dmitry A. Kazakov
2006-03-06 19:49         ` Stefan Lucks
2006-03-08 17:36         ` brian.b.mcguinness
2006-03-08 17:56           ` Jeff Carter
2006-03-09 22:36         ` Robert A Duff
2006-03-10  4:28           ` Jeffrey R. Carter
2006-03-10  8:46             ` Dmitry A. Kazakov
2006-03-10 17:33               ` Robert A Duff
2006-03-10 21:24                 ` Dmitry A. Kazakov
2006-03-10 17:38             ` Robert A Duff
2006-03-11  0:19               ` Randy Brukardt
2006-03-11  1:43                 ` Jeffrey R. Carter
2006-03-11  8:38                   ` Niklas Holsti
replies disabled

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