comp.lang.ada
 help / color / mirror / Atom feed
* 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

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