comp.lang.ada
 help / color / mirror / Atom feed
* Labeled exit within generalized labeled loop not allowed?
@ 2012-07-13 16:19 Marc C
  2012-07-13 17:21 ` Thomas Løcke
  2012-07-16  9:33 ` Thomas Løcke
  0 siblings, 2 replies; 9+ messages in thread
From: Marc C @ 2012-07-13 16:19 UTC (permalink / raw)


I find it hard to believe that this would be a GNAT GPL 2012 compiler bug, but I don't see anything in the LRM that indicates this wouldn't be legal.

Code containing a labeled generalized loop (the "for Elem of Some_Container" type), with a conditional exit referencing the loop label, fails to compile with an "Invalid loop name in exit statement" error.

What's the rationale for this? Or a consequence of what? Or is it a compiler bug?

Marc A. Criley

Here's an example:

with Text_IO; use Text_IO;

procedure Loop_Check is

   type Int_Array_Type is array (1..10) of Integer;
   
   IA : Int_Array_Type := (6 => 6, others => 3);
   
begin
   Loop_A: For I in IA'range loop
      Put_Line(Integer'Image(IA(I)));
      exit Loop_A When IA(I) = 6;
   end loop Loop_A;
   
   Loop_B: For I of IA loop
      Put_Line(Integer'Image(I));
      exit when I = 6;
   end loop Loop_B;
   
   Loop_C: For I of IA loop
      Put_Line(Integer'Image(I));
      exit Loop_C when I = 6; -- Compiler error on this line
   end loop Loop_C;
end Loop_Check;



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Labeled exit within generalized labeled loop not allowed?
  2012-07-13 16:19 Labeled exit within generalized labeled loop not allowed? Marc C
@ 2012-07-13 17:21 ` Thomas Løcke
  2012-07-16  9:33 ` Thomas Løcke
  1 sibling, 0 replies; 9+ messages in thread
From: Thomas Løcke @ 2012-07-13 17:21 UTC (permalink / raw)


On 07/13/2012 06:19 PM, Marc C wrote:
> I find it hard to believe that this would be a GNAT GPL 2012 compiler bug, but I don't see anything in the LRM that indicates this wouldn't be legal.
>
> Code containing a labeled generalized loop (the "for Elem of Some_Container" type), with a conditional exit referencing the loop label, fails to compile with an "Invalid loop name in exit statement" error.
>
> What's the rationale for this? Or a consequence of what? Or is it a compiler bug?


Yea, I got hit by that one also, and it's annoying as heck.

I need my loop labels, or my sanity will crumple. Yes, I'm that
fragile.  :D

-- 
Thomas L�cke | thomas@12boo.net | http://12boo.net





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Labeled exit within generalized labeled loop not allowed?
  2012-07-13 16:19 Labeled exit within generalized labeled loop not allowed? Marc C
  2012-07-13 17:21 ` Thomas Løcke
@ 2012-07-16  9:33 ` Thomas Løcke
  2012-07-16 10:33   ` Niklas Holsti
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas Løcke @ 2012-07-16  9:33 UTC (permalink / raw)


On 07/13/2012 06:19 PM, Marc C wrote:
> I find it hard to believe that this would be a GNAT GPL 2012 compiler bug, but I don't see anything in the LRM that indicates this wouldn't be legal.
>
> Code containing a labeled generalized loop (the "for Elem of Some_Container" type), with a conditional exit referencing the loop label, fails to compile with an "Invalid loop name in exit statement" error.
>
> What's the rationale for this? Or a consequence of what? Or is it a compiler bug?


Hmm, it appears we're the only people who experience this, or perhaps
the only people who care?  :D

I would've thought that labeled exits were something that were widely
used.

-- 
Thomas L�cke | thomas@12boo.net | http://12boo.net





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Labeled exit within generalized labeled loop not allowed?
  2012-07-16  9:33 ` Thomas Løcke
@ 2012-07-16 10:33   ` Niklas Holsti
  2012-07-16 12:03     ` Niklas Holsti
  0 siblings, 1 reply; 9+ messages in thread
From: Niklas Holsti @ 2012-07-16 10:33 UTC (permalink / raw)


On 12-07-16 12:33 , Thomas L�cke wrote:
> On 07/13/2012 06:19 PM, Marc C wrote:
>> I find it hard to believe that this would be a GNAT GPL 2012 compiler
>> bug, but I don't see anything in the LRM that indicates this wouldn't
>> be legal.
>>
>> Code containing a labeled generalized loop (the "for Elem of
>> Some_Container" type), with a conditional exit referencing the loop
>> label, fails to compile with an "Invalid loop name in exit statement"
>> error.
>>
>> What's the rationale for this? Or a consequence of what? Or is it a
>> compiler bug?
>
>
> Hmm, it appears we're the only people who experience this, or perhaps
> the only people who care?  :D

My guess is a compiler bug, not discovered earlier because the labeled 
exit statements are rare, and users of Ada 2012 also (so far).

> I would've thought that labeled exits were something that were widely
> used.

A data point on this:

I scanned an Ada 2005 project of mine. It has 893 loops but only 35 
labeled exit statements. These are always on large, complex loops, 
sometimes nested loops where the exit leaves the outermost loop from an 
innner loop. When these loops are traversing a data structure, the 
structure is usually dynamic (e.g. a work-list) that can shrink and grow 
during the execution of the loop.

This project has many loop exits from small traversal loops of fixed 
data structures. These loops could use the generalized loop syntax, but 
the loops are small and usually not nested, so they are not named.

To me, the generalized loop syntax suggests that the loop should be 
executed for all the elements in the container, that the amount of data 
in the container does not change during the loop, and that the traversal 
order is not important. I know that the order is defined; I am talking 
about my impression while reading the program. I'm not sure if data can 
be added to or removed from a container during a generalized iteration 
over the container; would that be "tampering"?

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Labeled exit within generalized labeled loop not allowed?
  2012-07-16 10:33   ` Niklas Holsti
@ 2012-07-16 12:03     ` Niklas Holsti
  2012-07-16 12:29       ` Thomas Løcke
  2012-07-19  6:41       ` Randy Brukardt
  0 siblings, 2 replies; 9+ messages in thread
From: Niklas Holsti @ 2012-07-16 12:03 UTC (permalink / raw)


I forgot to state my conclusion explicitly (at the end, below):

On 12-07-16 13:33 , Niklas Holsti wrote:
> On 12-07-16 12:33 , Thomas L�cke wrote:
>
>> I would've thought that labeled exits were something that were widely
>> used.
>
> A data point on this:
>
> I scanned an Ada 2005 project of mine. It has 893 loops but only 35
> labeled exit statements. These are always on large, complex loops,
> sometimes nested loops where the exit leaves the outermost loop from an
> innner loop. When these loops are traversing a data structure, the
> structure is usually dynamic (e.g. a work-list) that can shrink and grow
> during the execution of the loop.
>
> This project has many loop exits from small traversal loops of fixed
> data structures. These loops could use the generalized loop syntax, but
> the loops are small and usually not nested, so they are not named.
>
> To me, the generalized loop syntax suggests that the loop should be
> executed for all the elements in the container, that the amount of data
> in the container does not change during the loop, and that the traversal
> order is not important. I know that the order is defined; I am talking
> about my impression while reading the program. I'm not sure if data can
> be added to or removed from a container during a generalized iteration
> over the container; would that be "tampering"?

The conclusion is that I (as one example of an Ada programmer) usually 
would not code an exit statement (whether labeled or unlabeled) in a 
simple loop that uses the generalized loop syntax, because then the loop 
would not process all the elements in the container.

Vice versa, I would also be unlikely to use the generalized loop syntax 
for a loop that needs a labeled exit statement, because such a loop is 
likely to be more complex and dynamic than seems suitable (to me) for 
the generalized loop syntax. Moreover, an exit statement usually means 
that iteration order is important, which I (subjectively) do not 
associate with the generalized syntax.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Labeled exit within generalized labeled loop not allowed?
  2012-07-16 12:03     ` Niklas Holsti
@ 2012-07-16 12:29       ` Thomas Løcke
  2012-07-16 15:24         ` Marc C
  2012-07-19  6:41       ` Randy Brukardt
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas Løcke @ 2012-07-16 12:29 UTC (permalink / raw)


On 07/16/2012 02:03 PM, Niklas Holsti wrote:
> I forgot to state my conclusion explicitly (at the end, below):
>> To me, the generalized loop syntax suggests that the loop should be
>> executed for all the elements in the container, that the amount of data
>> in the container does not change during the loop, and that the traversal
>> order is not important. I know that the order is defined; I am talking
>> about my impression while reading the program. I'm not sure if data can
>> be added to or removed from a container during a generalized iteration
>> over the container; would that be "tampering"?
>
> The conclusion is that I (as one example of an Ada programmer) usually
> would not code an exit statement (whether labeled or unlabeled) in a
> simple loop that uses the generalized loop syntax, because then the loop
> would not process all the elements in the container.
>
> Vice versa, I would also be unlikely to use the generalized loop syntax
> for a loop that needs a labeled exit statement, because such a loop is
> likely to be more complex and dynamic than seems suitable (to me) for
> the generalized loop syntax. Moreover, an exit statement usually means
> that iteration order is important, which I (subjectively) do not
> associate with the generalized syntax.



To me, the new generalized loops are mostly syntactic sugar. I don't
associate them with loops where the loop _must_ be executed for all
elements.

I think you're right: It's probably an undiscovered compiler bug due
to low usage of the feature. But low usage does not equal no usage.

I want my named exit statements back!  :D

-- 
Thomas L�cke | thomas@12boo.net | http://12boo.net





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Labeled exit within generalized labeled loop not allowed?
  2012-07-16 12:29       ` Thomas Løcke
@ 2012-07-16 15:24         ` Marc C
  2012-07-17  6:01           ` Thomas Løcke
  0 siblings, 1 reply; 9+ messages in thread
From: Marc C @ 2012-07-16 15:24 UTC (permalink / raw)


On Monday, July 16, 2012 7:29:43 AM UTC-5, Thomas Løcke wrote:

> I think you're right: It's probably an undiscovered compiler bug due
> to low usage of the feature. But low usage does not equal no usage.

Reported this to AdaCore and received confirmation that it's a bug.  Got missed because there's not been a lot of user experience with the Ada 2012 features yet.

> I want my named exit statements back!  :D

GNAT GPL 2013 :-)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Labeled exit within generalized labeled loop not allowed?
  2012-07-16 15:24         ` Marc C
@ 2012-07-17  6:01           ` Thomas Løcke
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Løcke @ 2012-07-17  6:01 UTC (permalink / raw)


On 07/16/2012 05:24 PM, Marc C wrote:
> Reported this to AdaCore and received confirmation that it's a bug.  Got missed because there's not been a lot of user experience with the Ada 2012 features yet.


YAY!


> GNAT GPL 2013 :-)


I'm a patient guy. I can handle the wait.

/me stares blankly at monitor

-- 
Thomas L�cke | thomas@12boo.net | http://12boo.net





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Labeled exit within generalized labeled loop not allowed?
  2012-07-16 12:03     ` Niklas Holsti
  2012-07-16 12:29       ` Thomas Løcke
@ 2012-07-19  6:41       ` Randy Brukardt
  1 sibling, 0 replies; 9+ messages in thread
From: Randy Brukardt @ 2012-07-19  6:41 UTC (permalink / raw)


"Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message 
news:a6ie8cFfi4U1@mid.individual.net...
...
> The conclusion is that I (as one example of an Ada programmer) usually 
> would not code an exit statement (whether labeled or unlabeled) in a 
> simple loop that uses the generalized loop syntax, because then the loop 
> would not process all the elements in the container.

The AARM specifically suggests using an exit statement if you need to just 
handle part of a container. See A.18.2(230.a-c/3).

That's the justification for why there is an iterator form that has a start 
location, but no iterator with a stop location. (Beyond the fact that there 
are problems if the stop location is not in the container.)

So it is intended that such exits be used. I'd expect the need to be 
relatively rare, but certainly not non-existent.

                              Randy.





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-07-25  3:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-13 16:19 Labeled exit within generalized labeled loop not allowed? Marc C
2012-07-13 17:21 ` Thomas Løcke
2012-07-16  9:33 ` Thomas Løcke
2012-07-16 10:33   ` Niklas Holsti
2012-07-16 12:03     ` Niklas Holsti
2012-07-16 12:29       ` Thomas Løcke
2012-07-16 15:24         ` Marc C
2012-07-17  6:01           ` Thomas Løcke
2012-07-19  6:41       ` Randy Brukardt

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