comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: API design considerations - variable-length array in record type
Date: Tue, 09 Oct 2012 08:42:08 +0300
Date: 2012-10-09T08:42:08+03:00	[thread overview]
Message-ID: <adhrpgF2l6eU1@mid.individual.net> (raw)
In-Reply-To: <86a6f9d1-c99f-4184-aa79-ab7c15af9d4c@googlegroups.com>

On 12-10-09 05:02 , Shark8 wrote:
> On Monday, October 8, 2012 3:03:04 AM UTC-6, Maciej Sobczak wrote:
>>
>> type R is record
>>    X : Integer;
>>    Y : Unbounded_String;
>>    Z : Array_Of_Integers_That_We_Talk_About_Here;
>> end record;
>>
>> Requirements:
>> 1 - the enclosing record type should not be limited (it should be copyable)
>> 2 - the record type can be explicitly controlled, if necessary
>> 3 - the record type should be definite (it should not require initialization)
>> 4 - it should be possible to assign to Z, just as it is possible to assign to X and Y, and the new value for Z *might have a different length* 
> 
> Why not use discriminants on the record?
> 
> Default : Constant := Natural'First;
> type R( Array_Length : Natural:= Natural'First ) is record
>    X : Integer;
>    Y : Unbounded_String;
>    Z : Array_Of_Integers_That_We_Talk_About_Here(1..Array_Length):= (Others => Default);
> end record;

Requirement 4 is not satisfied: if you assign a new value to R.Z, it has
to have the same length as the old value (R.Array_Length). You can
change the length only by assigning a new value, with the new discrimant
value, to the whole record.

And there is the memory usage problem that Adam described.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .



  parent reply	other threads:[~2012-10-16  1:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08  9:03 API design considerations - variable-length array in record type Maciej Sobczak
2012-10-08 11:13 ` Simon Wright
2012-10-08 11:29 ` Egil Høvik
2012-10-08 11:53   ` Maciej Sobczak
2012-10-08 14:37     ` Tero Koskinen
2012-10-09  2:02 ` Shark8
2012-10-09  5:16   ` Adam Beneschan
2012-10-09  5:45     ` Shark8
2012-10-09  5:42   ` Niklas Holsti [this message]
2012-10-09  3:10 ` Stephen Leake
2012-10-09  7:47   ` Maciej Sobczak
replies disabled

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