comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to best make a custom range?
Date: Mon, 4 Nov 2019 22:41:50 +0100
Date: 2019-11-04T22:41:50+01:00	[thread overview]
Message-ID: <qpq5us$a47$1@gioia.aioe.org> (raw)
In-Reply-To: 72cf1559-a51f-4a7d-a79e-fe349f833883@googlegroups.com

On 2019-11-04 20:13, Shark8 wrote:
> On Monday, November 4, 2019 at 11:55:42 AM UTC-7, Dmitry A. Kazakov wrote:
>> On 2019-11-04 19:49, Andrew Shvets wrote:
>>> Mostly to have a set of values that I can select at random.
>>
>> That is not subtype, which is the point. If it were made a "subtype" as
>> was suggested per misuse of dynamic predicate,
> It's not Dynamic_Predicate, it's Static_Predicate.
> 
>> then that would break
>> most of the code by polluting it with Constraint_Error raised in most
>> unexpected places.
> Constraint_Error is the normal/expected exception, perhaps you are thinking Assertion_Error?

No difference. So long an unanticipated exception is propagated it is a 
bug. Any new dynamic check is a bug.

>> Which is the reason why it should not be a subtype,
>> because it is not (see LSP).
> Everywhere that Character is requested, a Test_Character is valid

Try

    Lookup : array (Test_Character) of Boolean := (others => False);

or

    procedure Next (X : in out Character) is
    begin
       X := Character'Succ (X);
    end Next;

in case you tried to implement arrays indexed by arbitrary subsets...

> Just like everywhere Integer is requested, Natural is valid.

Consider:

    procedure Negate (Value : in out Integer);

Natural is valid there only when 0.

Yes, the type system will pass it through, and this is the problem. You 
do not known in advance which code will change its behavior. With proper 
ranges it is doable to foresee most of the cases especially because base 
types are ranges too. Arbitrary constraints break arbitrary pieces of code.

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

      reply	other threads:[~2019-11-04 21:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-04 17:26 How to best make a custom range? Andrew Shvets
2019-11-04 17:56 ` Shark8
2019-11-04 18:49   ` Andrew Shvets
2019-11-04 19:16   ` Shark8
2019-11-05 14:02     ` Andrew Shvets
2019-11-05 15:10       ` Shark8
2019-11-08 15:55         ` AdaMagica
2019-11-08 16:07           ` AdaMagica
2019-11-08 22:28           ` Randy Brukardt
2019-11-05 17:14       ` Dmitry A. Kazakov
2019-11-05 17:28         ` Shark8
2019-11-04 18:34 ` Dmitry A. Kazakov
2019-11-04 18:49   ` Andrew Shvets
2019-11-04 18:55     ` Dmitry A. Kazakov
2019-11-04 19:13       ` Shark8
2019-11-04 21:41         ` Dmitry A. Kazakov [this message]
replies disabled

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