From: Dmitry A. Kazakov on
On Wed, 23 Apr 2008 12:42:32 +0200, Georg Bauhaus wrote:

> But how about this:
>
> procedure Ex is
> type E is (A, B, C);
> X: E;
> begin
> X := E'pred(E'succ(C));
> end Ex;
>
> In this case there is a static constraint error. Is this
> consistent with anything but the Ada LRM's exception for
> "integer convenience"?

But enumeration is finite. If we had extensible enumerations then it would
be reasonable to consider the set of enumeration values infinite, similarly
to signed integers.

Probably it could be possible to formalize such things by allowing the user
to describe certain properties of primitive operations. The case (A + B)
mod C relies on the group property of "+" and "mod":

forall n (A + nC) mod C = A mod C

There exists properties Ada compiler knows. For example:

forall private T, (not X=Y) = (X/=Y)

But it does not know that X - Y = X + (-Y), etc.

Also, supertyping should help. The anonymous types before the first named
subtype is nothing but a supertype, if you wanted to expose it. In the
cases when the user defines a primitive operation, the stuff like above
could to be defined in terms of the supertype or the class of
(contravariant).

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: christoph.grein on
> procedure Ex is
>     type E is (A, B, C);
>     X: E;
> begin
>     X := E'pred(E'succ(C));
> end Ex;

You can have this:

type Enum is (A, B, C, D);
type Sub is new Enum range A .. C;

Sub'Succ (Sub'Last) = D
Sub'Pred (Sub'Succ (Sub'Last)) = C

Sub'Base has range A .. D.
From: Peter Hermann on
Adam Beneschan <adam(a)irvine.com> wrote:
> was a darn good reason why they did it that way. In this particular
> case, I think they saw a need to support static expressions with
> intermediate results that were larger than a machine integer, and the

which is one of the many advantages of Ada.

BTW (changing topic):
I am still hoping that the next Ada 2015 will contain

subtype Number_Base is Integer range 2 .. 36; -- old:16;

in Ada.Text_IO for practical reasons, see

www.ada-auth.org/cgi-bin/cvsweb.cgi/ACs/AC-00070.TXT?rev=1.1



From: Georg Bauhaus on
christoph.grein(a)eurocopter.com schrieb:
>> procedure Ex is
>> type E is (A, B, C);
>> X: E;
>> begin
>> X := E'pred(E'succ(C));
>> end Ex;
>
> You can have this:
>
> type Enum is (A, B, C, D);
> type Sub is new Enum range A .. C;
>
> Sub'Succ (Sub'Last) = D
> Sub'Pred (Sub'Succ (Sub'Last)) = C
>
> Sub'Base has range A .. D.

Yes, but extending the set of values only shifts the
(theoretical) problem of 'Succ by one inductive step.
Once we forget about the type of unrepresentable numbers
the problem ceases to exist, I think.
From: Dmitry A. Kazakov on
On Wed, 23 Apr 2008 13:14:24 +0000 (UTC), Peter Hermann wrote:

> BTW (changing topic):
> I am still hoping that the next Ada 2015 will contain
>
> subtype Number_Base is Integer range 2 .. 36; -- old:16;

You should have asked for more, much MORE! I mean, characters from
identifier_start + number_decimal - '0' (see Ada 2005 RM 2.3). If anybody
needed that thing, of course... (:-))

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