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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "Alejandro R. Mosteo" Newsgroups: comp.lang.ada Subject: Peculiarities of "of" syntax Date: Sat, 11 Jan 2020 19:05:21 +0100 Organization: A noiseless patient Spider Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 11 Jan 2020 18:05:21 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="da7567c67b32997687b50220fc8fb9e2"; logging-data="26516"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/KSqcq4F8B7r347M/p2FeG" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 Cancel-Lock: sha1:bdhhrqfBjnHxovzXimkMcWxcfWc= Content-Language: en-US X-Mozilla-News-Host: news://news.eternal-september.org:119 Xref: reader01.eternal-september.org comp.lang.ada:57827 Date: 2020-01-11T19:05:21+01:00 List-Id: Apologies if I asked this in the past. Sometimes I compose posts in my head and later forget to actually do anything about it. The following GNAT 2019-rejected examples of iterating with the new "of" are giving me some pause if this is an oversight in the feature, a bug in the compiler, or actually intended for some good reason: procedure Pro is type Int_Array is array (Positive range <>) of Integer; Arr : Int_Array := (others => 0); begin -- 1) for Z of Arr loop -- of course valid null; end loop; -- 2) for Z of Int_Array'(Arr & Arr) loop -- also works null; end loop; -- INVALID -- 3) for Z of Arr & Arr loop -- Error is "missing loop" null; end loop; -- 4) for Z of (Arr & Arr) loop -- Error is "name expected" null; end loop; end Pro; The crux of the matter might be in 5.5.2, where an "iterator_name" appears: iterator_specification ::= defining_identifier in [reverse] iterator_name | defining_identifier [: subtype_indication] of [reverse] iterable_name http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-5-5-2.html I get lost there; iterator_name links to "name" and stops there. In the AARM I was unable to find any obvious help and the original AI [0] actually says: "The second [grammar production] requires an expression returning an array, or an object of a type which has aspects Default_Iterator and Iterator_Element specified" and "the expected type for the /array_/name is any array type." A note here: these examples are with arrays for simplicity but I'm finding the problem with a custom "&" that returns iterable types, so the wording that applies is just after the previous phrase: "the expected type for the /iterable_/name is any iterable type" (I don't think that makes any difference anyway, but just in case). From some other related question [1] I need to review the master rules in 7.6, but my first instinct is that 3) and 4) could be legal if the loop is the master of the expression. In conclusion: any insight on what's going on with 3) and 4)? Thanks! [0] http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai05s/ai05-0139-2.txt?rev=1.22&raw=N [1] https://groups.google.com/d/msg/comp.lang.ada/veW6BNBGBfo/gDFwEsyyAgAJ