From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: Ada case-statement
Date: Thu, 15 Mar 2018 13:40:23 -0700 (PDT)
Date: 2018-03-15T13:40:23-07:00 [thread overview]
Message-ID: <d026e805-e6a6-4c3e-9128-d33958e49cbf@googlegroups.com> (raw)
In-Reply-To: <854a959a-baa6-4ce3-82bf-031f20e3abaa@googlegroups.com>
On Thursday, March 15, 2018 at 11:50:19 AM UTC-7, Jere wrote:
> On Thursday, March 15, 2018 at 11:37:48 AM UTC-4, Stephen Davies wrote:
> > On Wednesday, 14 March 2018 23:16:29 UTC, Randy Brukardt wrote:
> >
> > > declare
> > > Selector : Day_Type renames Calculate_Day;
> > > subtype Weekend_Subtype is Day_Type range Sat .. Sun;
> > > -- Or use a static predicate if the range is discontiguous.
> > > begin
> > > case Selector is
> > > when Mon .. Fri =>
> > > ...
> > > when Sat | Sun =>
> > > ...
> > > case Weekend_Subtype'(Selector) is -- A type conversion works, too.
> > > when Sat =>
> > > ...
> > > when Sun =>
> > > ...
> > > end case;
> > > end case;
> > > end;
> >
> > Unless this has changed in more recent compilers, the static predicate
> > when Sat & Sun are not contiguous does not work. Gnatpro 7.0.2 complains
> > about missing values. Also, attempting to use "when Weekend_Subtype" in
> > the outer case-statement results in complaints about duplicate values.
>
> I just tried a quick example in GNAT 6.1.1 and 7.2.0 and both seemed pretty
> happy with static predicates. I don't have 7.0.2 to check
>
> procedure jdoodle is
> type Day is (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday);
> subtype Weekday is Day range Monday .. Friday;
> subtype Weekend is Day
> with Static_Predicate => Weekend in Saturday | Sunday;
>
> v : Day := Monday;
> begin
>
> case v is
> when Weekday =>
> case Weekday(v) is
> when Monday => null;
> when Tuesday => null;
> when Wednesday => null;
> when Thursday => null;
> when Friday => null;
> end case;
>
> when Weekend =>
> case Weekend(v) is
> when Saturday => null;
> when Sunday => null;
> end case;
> end case;
>
> end jdoodle;
>
> no warnings or errors for either version
It compiles fine with GNAT-GPL-2017 running on Windows, too.
Anh Vo
next prev parent reply other threads:[~2018-03-15 20:40 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-14 17:35 Ada case-statement Stephen Davies
2018-03-14 17:49 ` Dmitry A. Kazakov
2018-03-15 0:57 ` Robert I. Eachus
2018-03-15 3:10 ` Dan'l Miller
2018-03-15 5:54 ` J-P. Rosen
2018-03-15 7:56 ` Niklas Holsti
2018-03-15 12:21 ` Dan'l Miller
2018-03-15 17:22 ` Mill processor (Was: Re: Ada case-statement) Niklas Holsti
2018-03-15 21:50 ` Ada case-statement Randy Brukardt
2018-03-14 22:22 ` Mehdi Saada
2018-03-14 23:16 ` Randy Brukardt
2018-03-15 5:04 ` gautier_niouzes
2018-03-15 7:50 ` Jacob Sparre Andersen
2018-03-15 22:05 ` Randy Brukardt
2018-03-15 8:37 ` Dmitry A. Kazakov
2018-03-15 22:20 ` Randy Brukardt
2018-03-16 8:54 ` Dmitry A. Kazakov
2018-03-16 23:49 ` Randy Brukardt
2018-03-17 7:59 ` Dmitry A. Kazakov
2018-03-15 15:37 ` Stephen Davies
2018-03-15 16:33 ` J-P. Rosen
2018-03-15 17:01 ` Dmitry A. Kazakov
2018-03-15 18:41 ` Shark8
2018-03-15 21:12 ` Jeffrey R. Carter
2018-03-18 5:41 ` Robert I. Eachus
2018-03-18 6:57 ` Spiros Bousbouras
2018-03-18 9:17 ` Jeffrey R. Carter
2018-03-18 12:53 ` Simon Wright
2018-03-15 18:50 ` Jere
2018-03-15 20:40 ` Anh Vo [this message]
2018-03-15 22:24 ` Randy Brukardt
2018-03-16 9:53 ` Stephen Davies
2018-04-03 17:56 ` marciant
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox