From: "Jeffrey R. Carter" <spam@spam.com>
Subject: Re: Half Constrained Array Types and Slices
Date: Fri, 03 Mar 2006 05:15:00 GMT
Date: 2006-03-03T05:15:00+00:00 [thread overview]
Message-ID: <ohQNf.401$x94.199@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <wccmzg8y43i.fsf@shell01.TheWorld.com>
Robert A Duff wrote:
>
> (Except my hobby language can use this idea to _simplify_, whereas Ada
> would have had to add this feature and still keep the "range <>"
> notation for compatibility.)
Right. I suppose you could introduce a notation like
Positive range 1 .. <>
to get a similar effect without having 2 ways to do an unconstrained array.
> I'm not so sure about that. I'm inclined to say slices always slide to
> the lower bound. The idea that X(3..5) should have lower bound 3 seems
> to make sense at first, until you think about passing that slice as a
> parameter. The called procedure should not care that it's a slice at
> all -- much less the particular bounds used to create it. The Ada rule
> violates abstraction. Same issue for function returns.
OK. So you're saying a slice (Lo .. Hi) of an unconstrained array type would
slide to Index'First .. Index'First + Hi - Lo?
> Yes, I agree that's a problem. Various possible solutions come to
> mind. Probably the simplest is to outlaw slices of constrained arrays.
> After all, what is the sense in saying "all arrays of type T go from
> 1 to 5", and then turn around and create values of type T with bounds
> 3..4? Even in Ada as is, there is very little use for this feature.
> You can do:
>
> type Bits is array(Int range 0..31) of Boolean;
>
> function Rotate(X: Bits) return Boolean Bits is
> begin
> return X(31) & X(0..30);
> end Rotate;
>
> But that's not worth much language complexity. If you want that,
> declare an unconstrained (doubly unconstrained?) array, along with
> constrained subtype(s).
That was the rule in Ada 83, IIRC. It apparently bit enough people that it was
changed in Ada 95.
> I can talk about more and more exotic ideas, depending on how far away
> from Ada you're willing to contemplate. ;-) For example, I'd like to
> be able to do:
>
> type T(D1: ...; D2: ...) is ...
> subtype S is T(D1 => 17); -- Illegal in Ada to partially constrain!
>
> Or maybe the syntax should be "T(D1 => 17, D2 => <>)".
In that case, this would be how you'd deal with slices of half-constrained
arrays if you wanted to keep the bounds; the base type would be unconstrained
and the first-named subtype would be partially constrained.
--
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14
next prev parent reply other threads:[~2006-03-03 5:15 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
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 [this message]
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