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.89.140 with SMTP id p134mr3536505itb.40.1521146424022; Thu, 15 Mar 2018 13:40:24 -0700 (PDT) X-Received: by 10.157.11.165 with SMTP id 34mr507033oth.7.1521146423942; Thu, 15 Mar 2018 13:40:23 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.linkpendium.com!news.linkpendium.com!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!r195-v6no77482itc.0!news-out.google.com!a25-v6ni150itj.0!nntp.google.com!e10-v6no77231itf.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 15 Mar 2018 13:40:23 -0700 (PDT) In-Reply-To: <854a959a-baa6-4ce3-82bf-031f20e3abaa@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=149.32.224.39; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 NNTP-Posting-Host: 149.32.224.39 References: <365d65ea-5f4b-4b6a-be9b-1bba146394ab@googlegroups.com> <854a959a-baa6-4ce3-82bf-031f20e3abaa@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Ada case-statement From: Anh Vo Injection-Date: Thu, 15 Mar 2018 20:40:24 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:51006 Date: 2018-03-15T13:40:23-07:00 List-Id: 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