comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Building an encapsulated library that uses GNAT sockets under Windows
Date: Thu, 28 Apr 2016 15:23:09 -0500
Date: 2016-04-28T15:23:09-05:00	[thread overview]
Message-ID: <nftrfe$n4p$1@loke.gir.dk> (raw)
In-Reply-To: nfrijv$k74$1@dont-email.me

"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:nfrijv$k74$1@dont-email.me...
> On 04/27/2016 03:16 PM, Randy Brukardt wrote:
>>
>>      loop
>>           {some code}
>>           if something then
>>               goto Continue;
>>           end if;
>>           {more code}
>>      <<Continue>> -- Ada 95 requires "null;" here, Ada 2012 does not.
>>      end loop;
>>
>> To completely eliminate the goto, one has to use a Boolean variable 
>> instead,
>> or duplicate parts of the loop; both of those obscure what is going on 
>> more
>> than the goto.
>
> This claim is completely untrue.
[Followed by a bunch of true, but irrelevant discussion.]

It's completely true, because, of course, the if is likely to be deeply 
nested inside of other if and case statements. I should probably have said 
that, but it is so plainly obvious I didn't think anyone would be so silly 
as to ignore and beat up on a straw man. But of course this is the Internet, 
where even usually reasonable people enjoy beating straw men...

A typical case would be a lexer for numeric literals, where one wants to 
discard the underscores and keep the other characters. That would look 
something like:

    while not End_of_File loop
         case Next_Char is
               when '0'..'9' =>
                     null;
               when '+' | '-' =>
                     {some code}
               when 'E' | 'e' =>
                     {some code}
               when '_' =>
                     if Last_Char = '_' then
                           Error (...);
                     else
                           goto Continue; -- Skip further processing.
                     end if;
              when others =>
                     exit; -- We've reached the end of the number.
         end case;
         {Store the Next_Char into the literal token}
      <<Continue>>
    end loop;

To avoid the goto/continue, you'd have to introduce a Boolean, or duplicate 
the "Store" code, or make the "Store" code into a subprogram, and make 
duplicate calls on that. None of which is clearer, or faster, than the above 
code. (Faster matters here as this loop is the third most used of the inner 
lexer loops, behind comments and identifiers. And a lexer is one of the top 
CPU users in a typical compiler.)

                                                     Randy.




  parent reply	other threads:[~2016-04-28 20:23 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21 12:59 Building an encapsulated library that uses GNAT sockets under Windows Dmitry A. Kazakov
2016-04-22  7:58 ` ahlan.marriott
2016-04-22  8:23   ` Dmitry A. Kazakov
2016-04-23  9:20     ` Ahlan
2016-04-23  9:48       ` Dmitry A. Kazakov
2016-04-23 14:45         ` ahlan.marriott
2016-04-23 19:56           ` Dmitry A. Kazakov
2016-04-23 21:16             ` Simon Wright
2016-04-24  8:13               ` ahlan
2016-04-24  8:31                 ` Simon Wright
2016-04-26 19:43                   ` ahlan.marriott
2016-04-26 20:24                     ` Simon Wright
2016-04-26 22:32                     ` Jeffrey R. Carter
2016-04-27 22:16                     ` Randy Brukardt
2016-04-27 23:43                       ` Jeffrey R. Carter
2016-04-28  5:18                         ` J-P. Rosen
2016-04-28  5:59                           ` Jeffrey R. Carter
2016-05-09 22:32                             ` David Thompson
2016-04-28 20:23                         ` Randy Brukardt [this message]
2016-04-28 21:47                           ` Jeffrey R. Carter
2016-04-28  5:13                       ` J-P. Rosen
2016-04-26 20:20               ` Dmitry A. Kazakov
2016-04-26 21:23                 ` Simon Wright
2016-04-27  6:53                   ` Simon Wright
2016-04-27  7:25                     ` ahlan
2016-04-27  8:27                   ` Dmitry A. Kazakov
2016-04-27  9:59                     ` Simon Wright
replies disabled

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