* Implementation of "=" (Ada83)
@ 1996-07-13 0:00 Matthew Heaney
1996-07-15 0:00 ` Jon S Anthony
0 siblings, 1 reply; 2+ messages in thread
From: Matthew Heaney @ 1996-07-13 0:00 UTC (permalink / raw)
I have a question about how to implement the "=" for limited private types
in Ada83.
Suppose we have
package T_Package is
type T is limited private;
function "=" (L, R : T) return Boolean;
private
type T is
record
A, B : Integer;
end record;
end;
package body T_Package is
function "=" (L, R : T) return Boolean is
begin
return ?; -- What goes here?
end;
end;
I think the LRM says that an equality operator is "implicitly declared" at
the point of declaration of the full view of the private type. Is this
correct? If so, how do I refer to it?
If I did this
function "=" (L, R : T) return Boolean is
begin
return L = R;
end;
isn't this just recursive?
Or do I just have to bite the bullet and do this
function "=" (L, R : T) return Boolean is
begin
return L.A = R.A and L.B = R.B;
end;
Is this the expected implementation?
There's one other implementation technique I thought of, that I don't
really like, but here it is:
package T_Package is
...
private
type T_Representation is
record
A, B : Integer;
end record;
type T is new T_Representation;
end;
package body T_Package is
function "=" (L, R : T) return Boolean is
begin
return T_Representation (L) = T_Representation (R);
end;
end;
At least here, I can directly refer to the "=" for the record itself, and
not to T's "=".
Maybe this is what the Ada language designers intended in this case?
Can anyone out there explain how they would implement the "=" for T?
Thanks a bunch!
matt
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
mheaney@ni.net
(818) 985-1271
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Implementation of "=" (Ada83)
1996-07-13 0:00 Implementation of "=" (Ada83) Matthew Heaney
@ 1996-07-15 0:00 ` Jon S Anthony
0 siblings, 0 replies; 2+ messages in thread
From: Jon S Anthony @ 1996-07-15 0:00 UTC (permalink / raw)
In article <mheaney-1307961304430001@news.ni.net> mheaney@ni.net (Matthew Heaney) writes:
> There's one other implementation technique I thought of, that I don't
> really like, but here it is:
> package T_Package is
>
> ...
>
> private
>
> type T_Representation is
> record
> A, B : Integer;
> end record;
>
> type T is new T_Representation;
>
> end;
>
> package body T_Package is
>
> function "=" (L, R : T) return Boolean is
> begin
> return T_Representation (L) = T_Representation (R);
> end;
>
> end;
This should work in both Ada83 and Ada95. Why don't you like it. Well,
OK, maybe it isn't the most aesthetic thing, but this is kind of a "gotcha"
in the language and you probably can't expect anything really clean...
> Can anyone out there explain how they would implement the "=" for T?
Probably as above. The trick is you have to separate the type definition
from the implementation. Another hack would be:
private
type T_Rep is ...
type T is record
The_Impl : T_Rep;
end record;
...
return L.The_Impl = R.The_Impl;
/Jon
--
Jon Anthony
Organon Motives, Inc.
1 Williston Road, Suite 4
Belmont, MA 02178
617.484.3383
jsa@organon.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-07-15 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-13 0:00 Implementation of "=" (Ada83) Matthew Heaney
1996-07-15 0:00 ` Jon S Anthony
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox