comp.lang.ada
 help / color / mirror / Atom feed
* overloading "=" (equal sign)
@ 1999-06-07  0:00 John
  1999-06-08  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 6+ messages in thread
From: John @ 1999-06-07  0:00 UTC (permalink / raw)


It looks like the "=" sign when overloaded, it asks for limited type
parameters only.
I guess by default.
So, I declare:
 type 'variable' is limited private;
 then,
private
    type 'variable' is new u32.un_integer;

Is there any way to pass non-limited parameters to my function ?
Or, is there any way to get rid of the private stuff ?
Thanx,
john






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overloading "=" (equal sign)
  1999-06-07  0:00 overloading "=" (equal sign) John
@ 1999-06-08  0:00 ` Matthew Heaney
  1999-06-08  0:00   ` Keith Thompson
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Heaney @ 1999-06-08  0:00 UTC (permalink / raw)


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.

> So, I declare:
>  type 'variable' is limited private;

I don't know what you mean by this, since this is not a legal Ada
declaration.

>  then,
> private
>     type 'variable' is new u32.un_integer;
> 
> Is there any way to pass non-limited parameters to my function ?

If you mean, Can an equality operator take non-limited types as
parameters, the answer is yes.

> Or, is there any way to get rid of the private stuff ?

Yes:


package P is

  type My_Integer is new Interfaces.Unsigned_32;

-- type My_Integer is mod 2**32;
-- (alternate declaration)

  function "=" (L, R : My_Integer) return Boolean;

end P;

package body P is

  function "=" (L, R : My_Integer) return Boolean is
  begin
    <impl here>
  end;

end P;



But I really don't know if this is what you want to do.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overloading "=" (equal sign)
  1999-06-08  0:00 ` Matthew Heaney
@ 1999-06-08  0:00   ` Keith Thompson
  1999-06-09  0:00     ` John
  0 siblings, 1 reply; 6+ messages in thread
From: Keith Thompson @ 1999-06-08  0:00 UTC (permalink / raw)


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.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overloading "=" (equal sign)
  1999-06-08  0:00   ` Keith Thompson
@ 1999-06-09  0:00     ` John
  1999-06-10  0:00       ` Bryce Bardin
  1999-06-10  0:00       ` Robert Dewar
  0 siblings, 2 replies; 6+ messages in thread
From: John @ 1999-06-09  0:00 UTC (permalink / raw)


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.






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overloading "=" (equal sign)
  1999-06-09  0:00     ` John
@ 1999-06-10  0:00       ` Bryce Bardin
  1999-06-10  0:00       ` Robert Dewar
  1 sibling, 0 replies; 6+ messages in thread
From: Bryce Bardin @ 1999-06-10  0:00 UTC (permalink / raw)


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;




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: overloading "=" (equal sign)
  1999-06-09  0:00     ` John
  1999-06-10  0:00       ` Bryce Bardin
@ 1999-06-10  0:00       ` Robert Dewar
  1 sibling, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1999-06-10  0:00 UTC (permalink / raw)


In article <7jmsgt$pqs$1@bgtnsc02.worldnet.att.net>,
  "John" <j.gonzale@worldnet.att.net> 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

Perhaps this is the straw that breaks the camel's back, and
now is the time for the proper "better" solution, which is
to update to Ada 95.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-06-10  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
1999-06-10  0:00       ` Robert Dewar

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