comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: loop and block question
Date: 1997/01/29
Date: 1997-01-29T00:00:00+00:00	[thread overview]
Message-ID: <E4s5Ht.MKF@world.std.com> (raw)
In-Reply-To: 1997Jan29.171423.3481@news.nbi.dk


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.




  reply	other threads:[~1997-01-29  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-29  0:00 loop and block question Jacob Sparre Andersen
1997-01-29  0:00 ` Robert A Duff [this message]
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
replies disabled

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