[net.lang.ada] Avoiding Recursion with Overloaded Operators

BBardin@ADA20.ISI.EDU (09/24/86)

In response to the question (from Pat Rogers at High Tech Lab) seeking a way 
to avoid a recursive call to an overloaded operator, consider:

package P is 

  type LP is limited private;

  function "=" (Left, Right : LP) return Boolean;

private

  type T is access Integer;
  type LP is new T;

end P;

package body P is 

  function "=" (Left, Right : LP) return Boolean is
  begin

    if T (Left) =  T (Right) or else
       Left.all =  Right.all then
    
      return True;

    else

      return False;

    end if;

  exception
    when Constraint_Error =>
      return False;

  end "=";

end P;

--------

Other (less desirable) solutions include testing 'Left.all' and
'Right.all' individually to see if the both generate constraint
errors, or (a little better) renaming the predefined operator before
overloading it.

The recommended solution was provided by Bryce Bardin, and has been
tested on a validated compiler.

Sincerely,

John Prentice
-------