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 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: array from static predicate on enumerated type Date: Wed, 17 Mar 2021 08:08:33 +0100 Organization: Aioe.org NNTP Server Message-ID: 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> NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader02.eternal-september.org comp.lang.ada:61571 List-Id: On 2021-03-17 05:05, Matt Borchers wrote: > It feels like an unfinished addition or incomplete feature to actively prevent 'First, 'Last, etc. from returning something reasonable about the sub-type in question. Return SOMETHING, even if it pertains to the parent type, and let the programmer decide how it can be useful to them. Using my LETTERS and CURVED_LETTERS example, I still don't see why the following would be problematic: > > A <= LETTERS'First > K <= LETTERS'Last > 11 <= LETTERS'Length > 1 <= LETTERS'Pos(B) > 10 <= LETTERS'Pos(J) > > B <= CURVED_LETTERS'First > J <= CURVED_LETTERS'Last > 5 <= CURVED_LETTERS'Length > 0 <= CURVED_LETTERS'Pos(B) > 4 <= CURVED_LETTERS'Pos(J) > > I didn't address 'Succ and 'Pred, but these also seem reasonable. Consider this: function Count (A : LETTERS) return Natural is Count : Natural := 0; begin for I in A'First..A'Last loop Count := Count + 1; end loop; end Count; How this supposed to be compiled? Note that CURVED_LETTERS is a subtype of LETTERS. So you can pass CURVED_LETTERS to Count. Count cannot use LETTERS'First, 'Succ etc in its body, they might be overridden they are like in CURVED_LETTERS. In short it must either dispatch on the actual argument or else the argument must be converted to LETTERS in a way that LETTERS operations would yield the correct result. Neither is possible. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de