comp.lang.ada
 help / color / mirror / Atom feed
* loop and block question
@ 1997-01-29  0:00 Jacob Sparre Andersen
  1997-01-29  0:00 ` Steve Jones - JON
  1997-01-29  0:00 ` Robert A Duff
  0 siblings, 2 replies; 5+ messages in thread
From: Jacob Sparre Andersen @ 1997-01-29  0:00 UTC (permalink / raw)



GNAT will not compile the inserted procedure, where I, in two different block
statements, declare two loops with the same loop statement identifier.

Is that because

 a) loop statement identifiers are globally known?
 b) identifiers declared within a block statement are globally known?
 c) that's how it is?
 d) GNAT has an annoying feature?

I have read sections 5.5 (Loop Statements) and 5.6 (Block Statements), but
they didn't make me much wiser.


Greetings,

Jacob
...
Jacob Sparre Andersen                            http://www.nbi.dk/%7Esparre/
Center for Chaos and Turbulence Studies          Phone: (+45) 39 65 53 51
The Niels Bohr Institute                                (+45) 35 32 53 05
...
LEGO: MOC+++c TO+++(6543) TC+++(8880) AQ+++ BV-- #++ S LS++ A-/+ YB72m
------------------------------------------------------------------------------
--  The example:

procedure Two_Loops is

begin

Block_1:
   begin

   Some_Loop_Name:
      for Index in 1 .. 10 loop
         null;
      end loop Some_Loop_Name;
   end Block_1;

Block_2:
   begin

   Some_Loop_Name:
      for Index in 1 .. 10 loop
         null;
      end loop Some_Loop_Name;
   end Block_2;
end Two_Loops;

------------------------------------------------------------------------------
--  Error messages from GNAT:
--
--  GNAT 3.05 (960607) Copyright 1991-1996 Free Software Foundation, Inc.
--  
--  Compiling: two_loops.adb (source file time stamp: 1997-01-28 11:02:36)
--  
--       8.    Some_Loop_Name:
--             |
--          >>> "Some_Loop_Name" conflicts with label at line 18
--  
--      17.    Some_Loop_Name:
--             |
--          >>> "Some_Loop_Name" conflicts with label at line 9
--  
--   22 lines: 2 errors
--  
------------------------------------------------------------------------------




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

* Re: loop and block question
  1997-01-29  0:00 loop and block question Jacob Sparre Andersen
@ 1997-01-29  0:00 ` Steve Jones - JON
  1997-01-29  0:00   ` Robert A Duff
       [not found]   ` <E4wHKC.FB5@thomsoft.com>
  1997-01-29  0:00 ` Robert A Duff
  1 sibling, 2 replies; 5+ messages in thread
From: Steve Jones - JON @ 1997-01-29  0:00 UTC (permalink / raw)



Bravely stepping forward from memory and with a question...
sparre@meyer.fys.ku.dk (Jacob Sparre Andersen) writes:
> 
> procedure Two_Loops is
> 
> begin
> 
> Block_1:
>    begin
> 
>    Some_Loop_Name:
>       for Index in 1 .. 10 loop
>          null;
>       end loop Some_Loop_Name;
>    end Block_1;
> 
> Block_2:
>    begin
> 
>    Some_Loop_Name:
You have reused Some_Loop_Name these labels should be unique just like the
compiler output tells you. Having never used the dreaded GOTO I cannot
be certain but I think that this is what the Labels COULD be used for
(if you wanted to die a slow and painful death).
[snip]

Now a question, why does Ada have GOTOs, why does code need to be changed
to avoid GOTOs problems ? I remember having a bunch of exception handling
blocks within a case statement, I had to create individual names for
each one rather than just using a unified label (eg Exception_Block)
we can overload everything BUT labels.

GOTO has unusual syntax so why not specific GOTO Labels ?

And yes this problem has manifested itself today due to some cutting
and pasting :(

-- 
Un Lupe en France  | Cat 1, Cha, Cha, Cha -- NERC offical drinking song
----The above of opinions rarely reflect my own and never my employers------
Do not add me to mailing lists violations will be billed for time.





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

* Re: loop and block question
  1997-01-29  0:00 ` Steve Jones - JON
@ 1997-01-29  0:00   ` Robert A Duff
       [not found]   ` <E4wHKC.FB5@thomsoft.com>
  1 sibling, 0 replies; 5+ messages in thread
From: Robert A Duff @ 1997-01-29  0:00 UTC (permalink / raw)



In article <2svi8g5rzr.fsf@hp755d2.eurocontrol.fr>,
Steve Jones - JON  <jon@hp755d2.eurocontrol.fr> wrote:
>You have reused Some_Loop_Name these labels should be unique just like the
>compiler output tells you. Having never used the dreaded GOTO I cannot
>be certain but I think that this is what the Labels COULD be used for
>(if you wanted to die a slow and painful death).

No.  Goto labels have a different syntax from loop names (and that's
good).  But they both have to follow the same unique-within-procedure
rule.

>Now a question, why does Ada have GOTOs,

Hey, are you trying to start a war?  ;-)

>... why does code need to be changed
>to avoid GOTOs problems ?

Good question.  I'm not entirely sure why loop and block names have to
obey the same rules as goto labels.

>... I remember having a bunch of exception handling
>blocks within a case statement, I had to create individual names for
>each one rather than just using a unified label (eg Exception_Block)
>we can overload everything BUT labels.

No.  At a given place in your code, you cannot overload two names,
unless *both* are subprograms.  This is a design principle of Ada 83,
for better or worse.  And to get around, the language definition
pretends that enumeration literals are "really" functions.  And to get
around it in a different way, integer literals are of some magical type
called universal_integer, and implicit conversions happen.

>GOTO has unusual syntax so why not specific GOTO Labels ?

The syntax of goto labels is different.  But goto labels occupy the same
namespace as everything else.  You can't have a variable called X and a
label called X in the same scope.  Are you saying that should be
allowed, and that overload resolution should distinguish "X := 1" and
"goto X;"?  IMHO, making the overload resolution rules too smart is not
a good idea.

- Bob




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

* Re: loop and block question
  1997-01-29  0:00 loop and block question Jacob Sparre Andersen
  1997-01-29  0:00 ` Steve Jones - JON
@ 1997-01-29  0:00 ` Robert A Duff
  1 sibling, 0 replies; 5+ messages in thread
From: Robert A Duff @ 1997-01-29  0:00 UTC (permalink / raw)



In article <1997Jan29.171423.3481@news.nbi.dk>,
Jacob Sparre Andersen <sparre@meyer.fys.ku.dk> wrote:
>GNAT will not compile the inserted procedure, where I, in two different block
>statements, declare two loops with the same loop statement identifier.

GNAT is correct.  See RM-5.1(11).  Statement_identifier means a
goto-label, or a block name, or a loop name, according to the syntax
rules.

>Is that because
>
> a) loop statement identifiers are globally known?

Not completely global, but more global than a single block.  All loop
names have to be unique, within a single procedure (for example).

> b) identifiers declared within a block statement are globally known?

No, just statement_identifiers.

> c) that's how it is?

Yes, that's how it is.  ;-)

> d) GNAT has an annoying feature?

Perhaps it's annoying, but it's what the RM says.  The rule is the same
as in Ada 83.  I guess the reasoning is to avoid confusion.  For goto
labels, that makes sense.  For loop and block names, I'm not so sure --
perhaps "annoying restriction" is appropriate.  On the other hand,
consider:

    procedure P is
    begin
        Loop_Name: loop
            declare
                ...
            begin
                Loop_Name: loop -- Illegal
                    ...
                    exit Loop_Name when ...; -- Would be confusing, if legal.
                end loop;
            end;
        end loop;
    end P;

5.1(11) prevents the above, although I'm inclined to believe that hiding
in general is to blame.  One should never be allowed to hide an outer
thing with an inner thing, IMHO.  Or, if you think hiding is useful, an
explicit "hide" statement should be in the language, rather than letting
you accidentally hide things just be declaring a name.

Your example doesn't involve hiding, and so seems reasonable to me.

>I have read sections 5.5 (Loop Statements) and 5.6 (Block Statements), but
>they didn't make me much wiser.

Look at 5.1.  In writing the RM, we tried to avoid writing the same rule
more than once, because we feared the consequences of multiple rules not
being in synch (the normal danger of duplicating code -- remember, the
RM was undergoing heavy maintenance during that time).  The problem is
that it makes it hard to find things -- you look at 5.5 about loop
names, and you don't know that we decided to hide the relevant rule in
5.1, which is about the more general concept of statement_names (among
other things).

>--       8.    Some_Loop_Name:
>--             |
>--          >>> "Some_Loop_Name" conflicts with label at line 18

- Bob

P.S. I wrote RM-5.1(11), and I also wrote the code in GNAT that gives
this error message.  So you can blame me, personally, for your troubles.
;-)

P.P.S. I think 5.1(11) adds a lot of unnecessary complexity to an Ada
compiler.  Ada 83 should have simply required pre-declaration of labels,
as does Pascal.  Gotos are not so commonly used that the burden of
writing an extra label decl is onerous.




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

* Re: loop and block question
       [not found]       ` <E4yCBo.FrC@world.std.com>
@ 1997-03-16  0:00         ` Niklas Holsti
  0 siblings, 0 replies; 5+ messages in thread
From: Niklas Holsti @ 1997-03-16  0:00 UTC (permalink / raw)



In <E4yCBo.FrC@world.std.com> bobduff@world.std.com (Robert A Duff) writes:

>In article <32F3D3BA.4B88@ssf.fi>, Niklas Holsti  <Niklas.Holsti@ssf.fi> wrote:
>>I found a surprising use for statement labels when automating the
>>timing measurements of an Ada program. A debugger script is used to
>>measure the time of a certain section of a subprogram. I delimited the
>>section to be measured with statement labels, thus:

>Sounds highly unreliable.  If there are no gotos, the compiler can
>freely move code across the labels, so any timing measurements are
>highly suspect.
 ...
>Highly questionable, IMHO, unless you looked at the machine code output,
>and verified that no code was moved past those labels.

Sure, I looked at the machine code output, but thanks for bringing out
the need to do so. For my uses, the timed code between the labels is
generally one or two subprogram calls.

>- Bob

Niklas Holsti                         
    Space Systems Finland Ltd, phone +358 9 6132 8625
    Keilaranta 8, FIN-02150 Espoo, Finland




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

end of thread, other threads:[~1997-03-16  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-29  0:00 loop and block question Jacob Sparre Andersen
1997-01-29  0:00 ` Steve Jones - JON
1997-01-29  0:00   ` Robert A Duff
     [not found]   ` <E4wHKC.FB5@thomsoft.com>
     [not found]     ` <32F3D3BA.4B88@ssf.fi>
     [not found]       ` <E4yCBo.FrC@world.std.com>
1997-03-16  0:00         ` Niklas Holsti
1997-01-29  0:00 ` Robert A Duff

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