comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: When is a rename not a rename?
Date: Fri, 1 Feb 2013 09:32:42 -0800 (PST)
Date: 2013-02-01T09:32:42-08:00	[thread overview]
Message-ID: <5ab43474-0ce2-425c-836b-ff4c97587958@googlegroups.com> (raw)
In-Reply-To: <coikrsq8nv3b$.1xcqe2olg7bpv$.dlg@40tude.net>

On Friday, February 1, 2013 3:27:02 AM UTC-8, Dmitry A. Kazakov wrote:
> On Fri, 1 Feb 2013 02:44:21 -0800 (PST), Ada novice wrote:
> 
> > If you have a minimal example that is proving the contrary, please post it here.
> 
> Here is how renaming is not renaming:

These examples aren't close to what I was getting at.  I was trying to talk about cases where Y renames X; but if you replace X in your program with Y, and both programs are legal, the program runs differently.  (Not counting cases where changing X to Y causes changes in the meanings of other identifiers later in the program because of the visibility rules.)

Your first two examples are cases where you can't use a rename because of the language rules, so these are definitely not the same thing.  In the first case, you just don't like how the scoping rules apply to exception handlers--it has nothing to do with renaming.  The second case is one that probably could be fixed by language rules, although I doubt it will happen.  It's mildly annoying that an ambiguous identifier error can be triggered by two identifiers with the same name that rename the same entity.  The third case is the opposite of what I'm talking about: if you replace X := -1 with Y := -1 the program has the exact same behavior.  It may be annoying that the rename allows you to put an additional constraint on the renaming variable and then ignores it.  I agree that it may have been a mistake to allow this.  But it's still not the same thing I was discussing.

Here's an example that may answer YC's question:

package Pack1 is
   pragma Elaborate_Body;
end Pack1;

with Ada.Text_IO;
package body Pack1 is
begin
   Text_IO.Put_Line ("Pack1 is elaborated");
end Pack1;

package Pack2 is
end Pack2;

with Pack1, Pack2;
package Pack3 renames Pack2;

with Pack2;  -- with Pack3;  <=== HERE
procedure Test is
begin
    null;
end Test;

If you run Test, nothing happens; but if you change the HERE line to "with Pack3;", then when you run Test, it outputs "Pack1 is elaborated", even though Pack3 renames Pack2.  That's what I was talking about.  Pack3 is not a strict "rename" in the sense that I understand the term (and apparently Randy likes to think of it as a wrapper of sorts rather than a strict rename).

Another possible example is when a subprogram renames another one but changes a default parameter:

    procedure P1 (N1 : Integer; N2 : Integer := 0) is ...

    procedure P2 (N1 : Integer; N2 : Integer := 1) renames P1;

    P1(5);
    P2(5);

Another case where P2 renames P1, but changing P1 to P2 has a different effect.  I think this capability was allowed deliberately, though, with the expectation that it might be useful.  Probably, if you do something like this, you should put comments on P2 to make it clear that this isn't a strict rename---and similarly on Pack3 in my earlier example.

                               -- Adam



  reply	other threads:[~2013-02-01 17:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-29  1:24 When is a rename not a rename? Adam Beneschan
2013-01-30  0:28 ` Randy Brukardt
2013-01-30  0:52   ` Adam Beneschan
2013-01-30  9:31     ` Dmitry A. Kazakov
2013-01-30 14:35       ` ytomino
2013-02-01 10:44 ` Ada novice
2013-02-01 11:27   ` Dmitry A. Kazakov
2013-02-01 17:32     ` Adam Beneschan [this message]
2013-02-01 18:31       ` ytomino
2013-02-02  1:40         ` Adam Beneschan
2013-02-02 12:24           ` ytomino
2013-02-02 14:26           ` Robert A Duff
2013-02-02 17:11             ` Shark8
2013-02-02  0:42       ` Brian Drummond
2013-02-02 11:43         ` AdaMagica
2013-02-03 11:50           ` Brian Drummond
2013-02-03 12:16             ` AdaMagica
2013-02-05  9:53       ` Ada novice
2013-02-01 17:48     ` Ada novice
replies disabled

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