From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: How to best make a custom range?
Date: Fri, 8 Nov 2019 07:55:14 -0800 (PST)
Date: 2019-11-08T07:55:14-08:00 [thread overview]
Message-ID: <bbdac1c2-53e9-4b26-a9da-580c988b6b1d@googlegroups.com> (raw)
In-Reply-To: <d49d78cb-a8ae-4646-ab95-4c6d715ceb28@googlegroups.com>
Am Dienstag, 5. November 2019 16:10:46 UTC+1 schrieb Shark8:
> TYPE Digits is range 0..9;
> SUBTYPE Odds is Digits with Static_Predicate => Odds in 1|3|5|7|9;
> what should Odds'Pred(1) be? 0? Constraint_Error?
> what about Odds'Pos(1) should it be 0, the first item of the subtype? Or 1, the position in the parent-type?
Attributes work on the base type, e.g.
Natural'Pred (0) = -1
Constraints on the subtype are ignored, Digit'Pred and Odds'Pred are identical. Thus:
Odds'Pred (8) = 7 -- 8-1
Odds'Pos (2) = 2 -- result is universal_integer
Of course, this will raise an exception:
X: Odds := Odds'Pred (7); -- 6 not in Odds
Y: Odds := Odds'Pos (8); -- universal_integer 8 converted into Digits not in Odds
next prev parent reply other threads:[~2019-11-08 15:55 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 [this message]
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox