comp.lang.ada
 help / color / mirror / Atom feed
From: "Alejandro R. Mosteo" <alejandro@mosteo.com>
Subject: Peculiarities of "of" syntax
Date: Sat, 11 Jan 2020 19:05:21 +0100
Date: 2020-01-11T19:05:21+01:00	[thread overview]
Message-ID: <qvd2p1$psk$1@dont-email.me> (raw)

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


             reply	other threads:[~2020-01-11 18:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-11 18:05 Alejandro R. Mosteo [this message]
2020-01-11 20:25 ` Peculiarities of "of" syntax Jeffrey R. Carter
2020-01-11 21:45 ` Robert A Duff
2020-01-12  1:38   ` Alejandro R. Mosteo
2020-01-12  2:01     ` Robert A Duff
2020-01-12 11:27     ` Simon Wright
2020-01-13 23:32     ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox