comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: syntaxic exploration
Date: Fri, 22 Dec 2017 17:45:22 -0600
Date: 2017-12-22T17:45:22-06:00	[thread overview]
Message-ID: <p1k5ek$8bj$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: b81c7f6f-dda7-4cd1-a9c6-953d0d30e7d4@googlegroups.com

<bj.mooremr@gmail.com> wrote in message 
news:b81c7f6f-dda7-4cd1-a9c6-953d0d30e7d4@googlegroups.com...
...
> Otherwise, one has to write a while loop, which is a bit awkward.
>
>   Position : Cursor := Cursor1;
>
>   Iteration_Loop :
>   loop
>       List (Position) := ...
>       exit Iteration_Loop when Position := Cursor2;
>       Next (Position);
>   end loop;

This works, of course.

>   One can almost do this with the current containers, with Ada 2012
>   iterator syntax because they generally
>   have an Iterate primitive that accepts a start cursor.
>
>   eg.
>
>   for I in List.Iterate(Start => Cursor1) loop
>      List (I) := ...
>   end loop;

This is true, too. But you just need to exit the loop at the end cursor to 
get the semantics you want:

   for I in List.Iterate(Start => Cursor1) loop
      List (I) := ...
      exit when I = Cursor2;
   end loop;

Ada doesn't care what kind of loop you use an exit in!

If there was to be a complaint here, it's that you can't easily use the 
element form ("of") with an ending cursor (because the cursor has to be 
explicit). But it seems weird to me to want to use cursors and yet hide them 
at the same time.

Conclusion: There isn't a need for an explicit "ending cursor", because an 
exit works fine for that in the cursor form. There still might be some sort 
of consistency argument, but we didn't add it originally since the exit is 
so easy to use for ending a loop "early".

                                 Randy.


  reply	other threads:[~2017-12-22 23:45 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-20 17:28 syntaxic exploration Mehdi Saada
2017-12-20 17:32 ` Mehdi Saada
2017-12-20 20:08   ` Niklas Holsti
2017-12-20 22:18     ` Mehdi Saada
2017-12-20 22:45       ` Mehdi Saada
2017-12-21  7:24         ` Randy Brukardt
2017-12-21  7:44           ` Niklas Holsti
2017-12-21  7:21   ` Randy Brukardt
2017-12-21 16:24     ` Jeffrey R. Carter
2017-12-22  5:01       ` Robert Eachus
2017-12-22 21:15         ` Simon Clubley
2017-12-22 22:11           ` Niklas Holsti
2017-12-22 22:51             ` Dmitry A. Kazakov
2017-12-23  7:15               ` Niklas Holsti
2017-12-23 16:23             ` Jeffrey R. Carter
2017-12-24  3:37               ` Robert Eachus
2017-12-24 13:39                 ` Niklas Holsti
2017-12-24 13:32               ` Niklas Holsti
2017-12-25 13:40                 ` Jeffrey R. Carter
2017-12-25 14:42                   ` Mehdi Saada
2017-12-25 17:03                     ` Dmitry A. Kazakov
2017-12-25 18:27                     ` Niklas Holsti
2017-12-25 20:12                     ` Jacob Sparre Andersen
2017-12-20 20:05 ` Niklas Holsti
2017-12-20 22:48 ` Mehdi Saada
2017-12-20 23:39   ` Mehdi Saada
2017-12-21  0:35 ` Mehdi Saada
2017-12-21  7:18 ` Randy Brukardt
2017-12-21 19:23   ` G. B.
2017-12-21 23:46   ` bj.mooremr
2017-12-22 23:45     ` Randy Brukardt [this message]
2017-12-22 13:31 ` Mehdi Saada
2017-12-22 18:00   ` Mehdi Saada
2017-12-22 18:27   ` Niklas Holsti
2017-12-22 20:25     ` Mehdi Saada
2017-12-22 22:33       ` Niklas Holsti
2017-12-23  1:47 ` Mehdi Saada
2017-12-23  7:17   ` Niklas Holsti
2017-12-23 11:23     ` Mehdi Saada
2017-12-23 11:39       ` Mehdi Saada
2017-12-23 12:09         ` Niklas Holsti
2017-12-23 12:12 ` Mehdi Saada
2017-12-23 12:16   ` Mehdi Saada
2017-12-23 13:04     ` Niklas Holsti
2017-12-23 14:02       ` Mehdi Saada
2017-12-23 14:46         ` Mehdi Saada
2017-12-23 15:03           ` Mehdi Saada
2017-12-23 22:11             ` Niklas Holsti
2017-12-24  0:55               ` Mehdi Saada
replies disabled

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