AdaCore / ada-spark-rfcs

Platform to submit RFCs for the Ada & SPARK languages
62 stars 28 forks source link

Box notation for array length discriminent in agregates #92

Open Fabien-Chouteau opened 2 years ago

Fabien-Chouteau commented 2 years ago

To be able to have String or any other kind of unconstrained array in a record I often use the following pattern:

type Data (Str_Len : Natural) is record
   Str : String (1 .. Str_Len);
end record;

This is convenient and works for me most of the time. However one annoying aspect is that when writing an aggregate one has to update the discriminant when changing the string. It's ok for short strings:

return (4, "test");
return (4, "But it is annoying for long string");

So I have two suggestions to discuss here: