comp.lang.ada
 help / color / mirror / Atom feed
From: Bryce Bardin <bbardin@home.com>
Subject: Re: overloading "=" (equal sign)
Date: 1999/06/10
Date: 1999-06-10T00:00:00+00:00	[thread overview]
Message-ID: <375F0A84.79B09B8@home.com> (raw)
In-Reply-To: 7jmsgt$pqs$1@bgtnsc02.worldnet.att.net

John wrote:
> 
> I think Keith is right since I'm using VADS Ada 83, for multi-thread.
> programming.
> I have a number of packages calling this operator, concurrently.
> If I make it 'limited private', I will have to go into every single package,
> and make them limited private types...
> sounds confusing, but any one has a better solution...to minimize work
> :-) ?
> Thanks
> John
> 
> Keith Thompson wrote in message ...
> >Matthew Heaney <matthew_heaney@acm.org> writes:
> >> On Mon, 7 Jun 1999 21:13:21 -0400, "John" <j.gonzale@worldnet.att.net>
> wrote:
> >>
> >> > It looks like the "=" sign when overloaded, it asks for limited type
> >> > parameters only.
> >>
> >> I'm not sure what you mean by this, becuase the equality operator does
> >> NOT have to take limited types as parameters.  Perhaps if you send some
> >> code, then we can determine what the problem is.
> >
> >I think Ada 83 had such a restriction.  There's a workaround using a
> >generic with a limited private type parameter; perhaps someone else
> >can remember the details.  (The existence of the workaround may have
> >been part of the motivation for removing the restriction in Ada 95.)
> >
> >--
> >Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
> >San Diego Supercomputer Center  <http://www.sdsc.edu>                 <*>
> >One of the great tragedies of ancient history is that Helen of Troy
> >lived before the invention of the champagne bottle.

The "Goodenough" technique for defining the "=" operator for non-limited
types in Ada83 is illustrated by the following example:

generic
  type Item is limited private; -- in Ada95, insert (<>)
  with function "=" (Left, Right : Item) return Boolean;
package Equality is

  package Inner is
    function "=" (Left, Right : Item) return Boolean 
        renames Equality."=";
  end Inner;

end Equality;

generic
  type Element is private;
package Bounded_Stack_Constructor is
  type Stack (Length : Natural) is private;
  function Is_Empty (The_Stack : Stack) return Boolean;
  function Equals (Left, Right : Stack) return Boolean;
    -- other operations 
private
  ...
end Bounded_Stack_Constructor;

with Equality;
with Bounded_Stack_Constructor;
generic

  type Element is private;

package Bounded_Stack is

  package Stack_Constructor is new Bounded_Stack_Constructor 
(Element);

  subtype Stack is Stack_Constructor.Stack;

  package Equals is new Equality (Stack_Constructor.Stack, 
                                  Stack_Constructor.Equals);
  function Is_Empty (The_Stack : Stack) return Boolean 
    renames Stack_Constructor.Is_Empty;

  function "=" (Left, Right : Stack) return Boolean renames 
Equals.Inner."=";

end Bounded_Stack;




  reply	other threads:[~1999-06-10  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-07  0:00 overloading "=" (equal sign) John
1999-06-08  0:00 ` Matthew Heaney
1999-06-08  0:00   ` Keith Thompson
1999-06-09  0:00     ` John
1999-06-10  0:00       ` Bryce Bardin [this message]
1999-06-10  0:00       ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox