From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.36.101.12 with SMTP id u12mr3422374itb.30.1521139817867; Thu, 15 Mar 2018 11:50:17 -0700 (PDT) X-Received: by 10.157.14.214 with SMTP id 80mr490252otj.9.1521139817493; Thu, 15 Mar 2018 11:50:17 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!peer02.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!e10-v6no17717itf.0!news-out.google.com!a25-v6ni24itj.0!nntp.google.com!r195-v6no16756itc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 15 Mar 2018 11:50:17 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.218.250; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.218.250 References: <365d65ea-5f4b-4b6a-be9b-1bba146394ab@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <854a959a-baa6-4ce3-82bf-031f20e3abaa@googlegroups.com> Subject: Re: Ada case-statement From: Jere Injection-Date: Thu, 15 Mar 2018 18:50:17 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Body-CRC: 3768688564 X-Received-Bytes: 3309 Xref: reader02.eternal-september.org comp.lang.ada:51003 Date: 2018-03-15T11:50:17-07:00 List-Id: 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