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:a37:596:: with SMTP id 144mr7271413qkf.387.1616112632286; Thu, 18 Mar 2021 17:10:32 -0700 (PDT) X-Received: by 2002:a5b:448:: with SMTP id s8mr2692708ybp.363.1616112632030; Thu, 18 Mar 2021 17:10:32 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.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 17:10:31 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=2601:193:4103:71a0:e984:a5fd:bb3c:1a8; posting-account=1tLBmgoAAAAfy5sC3GUezzrpVNronPA- NNTP-Posting-Host: 2601:193:4103:71a0:e984:a5fd:bb3c:1a8 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> <9933c99a-46b1-4541-aa15-f5c23e92b037n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: array from static predicate on enumerated type From: Matt Borchers Injection-Date: Fri, 19 Mar 2021 00:10:32 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:61620 List-Id: Dmitry, I don't think we can blatantly say that subtypes are types in every sense o= f the meaning. If they were distinct then there would be no difference bet= ween: subtype HEX_LETTERS is LETTERS range A..F; and type HEX_LETTERS is new LETTERS range A..F; when given: type LETTERS is ( A, B, C, D, E, F, G, H, I, J, K ); Please correct me if I am wrong, but I have always thought that the values = A through F in the sub-type were the same values of the parent type and are= effectively used interchangeably with the corresponding values of the pare= nt type. The sub-type simply provides a kind of restricted "view" constrai= nt. That is, the constraint checking used for variables of these types depe= nds on the type "view" of the variable. I don't know if I can explain myse= lf very well. I expected, therefore, that when a Static_Predicate was appl= ied to the sub-type, just a more complex constraint checking routine would = be applied rather that a simple "in range" check. >> I think you misunderstood me. Given the following, >> function L_POS( x : LETTERS ) return NATURAL is (LETTERS'Pos(x)); >> and >> function CL_POS( x : CURVED_LETTERS ) return NATURAL is (CURVED_LETTERS'= Pos(x)); >> >> I would have expected the following results: >> 1 <=3D l_pos(B) >> 0 <=3D cl_pos(B) >> 4 <=3D l_pos(E) >> exception <=3D cl_pos(E) > That would be a total catastrophe.=20 In regards to what L_POS and CL_POS return, I don't understand why that wou= ld be a catastrophe. Those values seem like reasonable answers to what the= programmer requested. This is really the point of this pose and my questi= on in the first place: What is the reason that there is absolutely no way = to implement useful results for 'First, 'Last, etc. with Static_Predicates?= And because of this, what is the best work-around? And I do feel like th= is requires a work-around. If CURVED_LETTERS with a predicate is not a sub-type, then it should not be= declared with a sub-type keyword. I like the word you used: subset. It s= hould have been: subset CURVED_LETTERS is LETTERS (B,C,D,G,J); And then Ada can be free to define a whole new set of rules for sub-sets wh= ile keeping sub-types consistent. Regards, Matt