comp.lang.ada
 help / color / mirror / Atom feed
From: Jeff Carter <jrcarter@acm.org>
Subject: Re: Redefined "=" = generic disaster?
Date: 2000/10/21
Date: 2000-10-21T00:00:00+00:00	[thread overview]
Message-ID: <39F1C092.87D4135E@acm.org> (raw)
In-Reply-To: 39F13ED9.1EE@li.net

Vincent Marciante wrote:
> generic
>     type Something is private;
> package Ada_83_Abstract_Data_Type is
>     type ADT is private;
>     ...
>     function Is_Equal (L,R: ADT) return Boolean;
> end;
> package body Ada_83_Abstract_Data_Type is
>     ...
>     function Is_Equal (L,R: ADT) return Boolean;
>     begin
>         return L = R;
>     end;
> end;

This is not valid Ada 83. Assuming we add a private part to the spec and
replace the ";" after "Boolean" with " is" in the body, you are invoking
the predefined "=" on the local type ADT, not the generic formal type
Something. Since we don't know the full definition of ADT, we don't know
what this has to do with "=" for Something. If ADT is a composite type
with one or more components of type Something, then "=" for ADT is
defined (at least partly) in terms of the predefined "=" for Something.

> BTW, I not interested in arguments that the old Ada 83 code was actually
> incorrect when it first written.  I am interested in finding out wats to
> update it so that it works as one would expect ;) in Ada 95.

Any generic that uses "=" for a generic formal type should explicitly
import "=" for the type:

generic -- Some_Package
   type T is private;
   with function "=" (Left : T; Right : T) return Boolean is <>;
package Some_Package is
...

> think of now is ethier add
> 
>   function "=" (L,R: Private_Type) return Boolean is "=";

The construct

   is "="

on a generic formal function (note that you need "with" before
"function") refers to a function named "=" that is visible when the
generic is compiled. Such a function is unlikely to exist for a generic
formal private type. To refer to a function "=" that is visible when the
generic is instantiated, which is probably what you wanted, use

   is <>

instead.

> P.S. Wow its late, I hope (all/most;) of the above makes sense!

Possibly.

-- 
Jeff Carter
"I waggle my private parts at your aunties."
Monty Python & the Holy Grail




  reply	other threads:[~2000-10-21  0:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-21  6:59 Redefined "=" = generic disaster? Vincent Marciante
2000-10-21  0:00 ` Jeff Carter [this message]
2000-10-21  0:00   ` Vincent Marciante
2000-10-28 11:12     ` Robert Dewar
2000-10-29  8:43       ` Vincent Marciante
2000-10-30  3:49       ` Lao Xiao Hai
2000-10-30 18:46         ` Robert Dewar
2000-10-31  3:27           ` Lao Xiao Hai
2000-10-31  6:54             ` Vincent Marciante
2000-10-31 19:51             ` Robert Dewar
2000-11-01 17:47               ` Mats Weber
2000-11-02  5:27                 ` Vincent Marciante
2000-11-02 16:52                   ` Mats Weber
2000-11-02 14:59                 ` Tucker Taft
2000-11-05  4:29                   ` Robert Dewar
2000-11-05  4:32                   ` Robert Dewar
2000-11-05  4:26                 ` Robert Dewar
2000-10-21  0:00   ` Vincent Marciante
2000-10-22  2:50     ` Jeff Carter
2000-10-22  0:00       ` Vincent Marciante
replies disabled

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