From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a05:620a:16ad:: with SMTP id s13mr4567072qkj.68.1616077501186; Thu, 18 Mar 2021 07:25:01 -0700 (PDT) X-Received: by 2002:a25:4ce:: with SMTP id 197mr11969579ybe.462.1616077500925; Thu, 18 Mar 2021 07:25:00 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.szaf.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 18 Mar 2021 07:25:00 -0700 (PDT) In-Reply-To: <7e1f3203-0fe9-428e-a8ac-411f432dca49n@googlegroups.com> Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: <89128f73-fcc5-4e57-8067-d09877ba0211n@googlegroups.com> <6ca041f3-2669-4497-9548-2f17666702a6n@googlegroups.com> <26c44e00-a899-455a-a929-1e23c7935fe3n@googlegroups.com> <9abb081d-a323-466d-9ae8-a2fc8fa24725n@googlegroups.com> <424f7220-abba-49df-8160-17851c336999n@googlegroups.com> <08b15573-0197-4b6e-9411-d0ca0f627f62n@googlegroups.com> <7e1f3203-0fe9-428e-a8ac-411f432dca49n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5b078796-0976-4303-a733-3eaa66637b07n@googlegroups.com> Subject: Re: array from static predicate on enumerated type From: Shark8 Injection-Date: Thu, 18 Mar 2021 14:25:01 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:61617 List-Id: On Wednesday, March 17, 2021 at 7:04:06 PM UTC-6, Matt Borchers wrote: > What I would expect is that P(12) would be an illegal access because 12 is not a valid value of Primes thus cannot be an index and a constraint error or out-of-range error would be thrown. Which is reasonable. > Wouldn't this just involve the compiler to insert "if x not in primes then raise..." if constraint checking is enabled? Possibly, there are also dynamic-predicates to consider; imagine a subtype wherein the usage of some number excludes that number from the subtype. Maybe a "unused_room_keys" subtype for a hotel. > Otherwise you have an erroneous program. Similarly, Primes'Succ(12) is also illegal. Primes'Pred(2) also illegal because there is no prime before 2 so presumably you have defined your Static_Predicate to enumerate the primes with 2 listed first. Why? Given the standard "subtype Natural is Integer range 0..Integer'Last" and "subtype Positive is Natural range Natural'Succ(Natural'First)..Natural'Last" Positive'Pred( 1 ) = 0, and no CONSTRAINT_ERROR. Do you want to break standard Ada usage?