From: leake@cme-durer.ARPA (Stephe Leake)
Subject: Re: Ada Language Change: Assignment Overloading
Date: 23 Nov 88 12:36:32 GMT [thread overview]
Message-ID: <743@marvin.cme-durer.ARPA> (raw)
In-Reply-To: karl@grebyn.com's message of 22 Nov 88 19:35:15 GMT
Thanks to Geoff Mendal for giving a careful, reasoned response to the
suggestion of allowing overloading of ":=". I would like to respond to
a couple of his points:
1. Why simply restrict it to assignment? ...
Good point; we need to consider each in turn, something I assume the
original language design team did. Where can I get the documentation
on their decisions?
2. Why is an overloading of assignment needed? ...
I stand guilty of sloppy thinking: I have accused others of not giving
specific examples of what changes would gain, and now I have none.
3. Overloading assignment will break virtually all Ada programs. ...
A very good point!
4. Finally, what would an overloading of assignment look like? ...
(consider the following program, is the "assignment" ambiguous)?
procedure Main is
type Int is new Integer;
type A1 is access Integer;
type A2 is access Int;
function F return A1 is begin ... end;
function F return A2 is begin ... end;
procedure ":=" (L : out Integer; R : in Integer) is
begin
...
end;
procedure ":=" (L : out Int; R : in Integer) is
begin
...
end;
begin
F.all := Integer'First; -- ambiguous?
end Main;
Note that the above program would be legal if the two ":=" procedure
bodies were removed.
The assignment is ambiguous because the second function F is not a
"pure" assignment; it is also a type conversion. All overloading is
subject to this type of abuse; the fact that it is also possible in
overloading assignment is not significant. In fact, carefull use of
this possibility could lead to more readable programs, by eliminating
lots of explicit type conversions (although my first reaction is that
the program should be restructured: explicit type conversions are
usually an indication that something is fundamentally wrong).
procedure Erroneous is
X : Integer;
procedure ":=" (L : out Integer; R : in Integer) is
begin
null;
end;
begin
X := Integer'First;
-- Does reference to X's value here make the execution of the
-- program erroneous?
end;
Yes, it is erroneous. But again, the problem is the idiotic definition
of ":="; the same idiotic definition could be given for "*", with
equally erroneous results. This is not unique to ":=". (Note that the
DEC compiler will issue a warning on compiling ":=", since the out
parameter is never given a value).
... Currently, if an assignment operation proceeds without
exception, then it must be the case that the variable name is assigned
the value specified (with some exceptions regarding assigning an
uninitialized object to another).
If we consider expressions results passed as actual parameters, the
same problem arrises with idiotic definitions of "*". I agree that
":=" seems more of a problem, but it is still not unique.
And yes, what would be the semantics of overloaded assignment for
task objects and predefined File_Type objects? Could it not be
the case here that current semantics would be broken through clever
use of overloading to assign limited objects?
These cannot be overloaded, since they are declared limited private in
packages that we cannot modify; just like other operators, assignment
for a limited private type should only be declarable in the same
declaration region the type is declared in.
The proponents of overloading assignment have also overlooked other
less costly solutions such as pre-processors that would transform
"overloaded assignment" into Ada procedure calls, implementation-defined
pragmas, etc.
These are definitely inferior solutions; if you want pre-processors,
use C! :-)
On the whole, I think the arguments in 2 and 3 are sufficient. I
hereby withdraw my request for overloading ":=". And thanks again for
the time spent.
Stephe Leake (301) 975-3431 leake@cme.nbs.gov
National Institute of Standards and Technology
(formerly National Bureau of Standards)
Rm. B-124, Bldg. 220
Gaithersburg, MD 20899
next prev parent reply other threads:[~1988-11-23 12:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1988-11-22 19:35 Ada Language Change: Assignment Overloading Karl Nyberg
1988-11-23 12:36 ` Stephe Leake [this message]
1988-11-23 19:13 ` Ray Trent
1988-11-23 22:57 ` William Thomas Wolfe,2847,
1988-11-24 2:16 ` William Thomas Wolfe,2847,
1988-11-24 1:55 ` William Thomas Wolfe,2847,
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox