From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Is this a bug?
Date: Fri, 3 Jan 2020 18:42:36 -0600
Date: 2020-01-03T18:42:36-06:00 [thread overview]
Message-ID: <quon1s$8ie$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: qumug8$1bsj$1@gioia.aioe.org
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:qumug8$1bsj$1@gioia.aioe.org...
> On 2020-01-03 08:35, reinert wrote:
...
>> But what is really the problem of prohibiting to include above:
>>
>> function a(x: rec1_t) return Integer is (5);
>>
>> ?
>>
>> This is similar to that the following is not legal:
>>
>> type rec1_t is tagged record
>> a : Integer := 2;
>> b : Integer := 2;
>> a : Integer := 5; -- is not legal.
>> end record;
>>
>> ?
>
> Yes, but that is was not possible, because in Ada 95 the function "a" did
> not conflict with members. The change in Ada 2005 introduced dot notation
> and thus the conflict.
It also doesn't really fix the problem unless one starts breaking privacy.
It's not just direct local declarations that cause problems, but also
inherited routines and class-wide routines associated with ancestors. And
since components can become visible at later points, you can also have
something that is legal in a specification be illegal in a body (especially
possible for child units).
For instance, if you have something like:
package P is
type Root is tagged private;
function C1 (A : Root) return Boolean;
function C2 (B : Root'Class) return Boolean;
private
type Root is tagged record
C3 : Natural;
end record;
end P;
Then, for
Obj : Root;
Obj.C1 and Obj.C2 are legal.
package P.Child is
type New_Type is new Root with record
??? : Natural;
end record;
function C3 (A : New_Type) return Boolean; -- Nope.
end P.Child;
New_Type cannot have components named C1 or C2, so if ??? has either of
those names, it has to be illegal. In addition, the function has to be
banned because the component C3 will be visible in the body of P.Child. (???
is illegal if it is C3.)
Because of the cases illustrated above, you also now have much more
significant maintenance problem. Imagine that P is some package out of your
control, like a GTKAda or even an Ada.Container package.
As Ada stands, one can add a subprogram to a package without having too
worry much about incompatibility. Conflicts are possible, but only matter if
the entire profile of the new subprogram matches. In cases like this, *any*
matching causes problems. That's because objects aren't overloadable in Ada,
so a component conflicts with any subprogram with the same name and prefix
parameter.
One can imagine making objects overloadable in Ada to avoid this problem
(the language would probably have been better if that had been the case),
but that can lead to the worst possible incompatibility: a program that
compiles and means something different than it does in current Ada. To avoid
that, you have to have some additional complex rules. And, of course if this
was done, we don't need the original rule at all (just let true conflicts
happen). So we're pretty much back where we started from.
In a language designed from the ground up to have this sort of prefix
notation for functions, there'd be no problem. But Ada isn't that language.
Randy.
next prev parent reply other threads:[~2020-01-04 0:42 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-30 15:44 Is this a bug? reinert
2019-12-30 17:51 ` Anh Vo
2019-12-30 18:41 ` Niklas Holsti
2019-12-30 19:50 ` reinert
2019-12-30 20:11 ` Dmitry A. Kazakov
2019-12-30 23:16 ` Randy Brukardt
2019-12-31 19:40 ` Optikos
2019-12-31 21:50 ` Randy Brukardt
2020-01-02 9:34 ` Dmitry A. Kazakov
2020-01-03 7:26 ` reinert
2020-01-03 7:35 ` reinert
2020-01-03 8:37 ` Dmitry A. Kazakov
2020-01-04 0:42 ` Randy Brukardt [this message]
2020-01-05 13:32 ` reinert
2020-01-06 10:43 ` J-P. Rosen
2020-01-06 12:19 ` Tero Koskinen
2020-01-17 9:54 ` reinert
2020-01-17 10:08 ` Dmitry A. Kazakov
2020-01-17 22:14 ` Randy Brukardt
2019-12-31 6:08 ` J-P. Rosen
-- strict thread matches above, loose matches on Subject: below --
2004-09-23 0:52 Wojtek Narczynski
2004-09-23 8:35 ` Wojtek Narczynski
2004-09-23 14:52 ` Nick Roberts
2004-09-23 22:26 ` Brian May
2004-09-24 0:28 ` Stephen Leake
2004-09-24 0:57 ` Jeffrey Carter
2004-09-24 12:47 ` Wojtek Narczynski
2004-09-25 0:17 ` Brian May
2004-09-24 12:37 ` Wojtek Narczynski
2004-09-23 11:27 ` Jeff C r e e.m
2004-09-24 0:30 ` Stephen Leake
2004-09-24 1:49 ` Jeff C r e e.m
2004-09-25 12:59 ` Stephen Leake
2004-10-04 16:36 ` Warren W. Gay VE3WWG
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox