🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.ada
Article #965

Avoiding Recursion with Overloaded Operators

#965
From: BBardin
Date: Wed, 24 Sep 1986 16:49
55 lines
1563 bytes
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
-------
Technical Details
Message-ID: <8609252230.AA03642@ucbvax.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!unisoft!dual!ucbvax!ADA20.ISI.EDU!BBardin

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!unisoft!dual!ucbvax!ADA20.ISI.EDU!BBardin
From: BBardin@ADA20.ISI.EDU
Newsgroups: net.lang.ada
Subject: Avoiding Recursion with Overloaded Operators
Message-ID: <8609252230.AA03642@ucbvax.Berkeley.EDU>
Date: Wed, 24-Sep-86 12:49:28 EDT
Article-I.D.: ucbvax.8609252230.AA03642
Posted: Wed Sep 24 12:49:28 1986
Date-Received: Fri, 26-Sep-86 18:43:41 EDT
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The ARPA Internet
Lines: 55