comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: specifying only 'First of an index in an array
Date: Wed, 3 Feb 2021 22:45:17 +0100	[thread overview]
Message-ID: <rvf5hf$o15$1@dont-email.me> (raw)
In-Reply-To: <3e30eef0-2d72-4b29-be1b-abdecc501a1an@googlegroups.com>

On 2/3/21 10:06 PM, Mehdi Saada wrote:
> I mean the possibility of specifying a minimal bound for index values, but not the outer bound.
> So still an array TYPE declaration constrained for one bound and not the other. And constrained fully at instanciation of course.

This was discussed here recently referring specifically to strings.

Since these are sequences, the index should be numeric with a lower bound of 1.

Ada has had a way to do this since Ada 83:

type T_Base is array (Positive range <>) of Element;

type T (Length : Natural) is record
    Value : T_Base (1 .. Length);
end record;

Ada 12 also adds the possibility of

subtype T is T_Base with
    Dynamic_Predicate => T'First = 1;

There is also the possibility of using a Vector for this.

The record has the advantage that sliding works, and the disadvantage that you 
have to put .Value in a lot of places.

The predicate has the advantage that it is an array type and objects can be 
indexed directly, and the disadvantage that sliding doesn't work.

Vectors have the advantage that the length can vary, and the disadvantages that 
slicing doesn't exist and conversions between Vector and T_Base are more complex 
than for the other forms.

-- 
Jeff Carter
"Sheriff murdered, crops burned, stores looted,
people stampeded, and cattle raped."
Blazing Saddles
35

  reply	other threads:[~2021-02-03 21:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 17:47 specifying only 'First of an index in an array Mehdi Saada
2021-02-03 19:29 ` Jeffrey R. Carter
2021-02-03 21:06   ` Mehdi Saada
2021-02-03 21:45     ` Jeffrey R. Carter [this message]
2021-02-03 22:15       ` Mehdi Saada
replies disabled

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