comp.lang.ada
 help / color / mirror / Atom feed
From: cis.ohio-state.edu!math.ohio-state.edu!darwin.sura.net!spool.mu.edu!agate
Subject: Re: Ada 9X: Eliminating the re-emergence of predefined operations
Date: 14 Sep 93 19:53:07 GMT	[thread overview]
Message-ID: <1993Sep14.212549@lglsun.epfl.ch> (raw)

In article <CDBqDH.HqF@irvine.com>, adam@irvine.com (Adam Beneschan) writes:
|> 
|> It seems to me that this can be worked around by doing the following.
|> However, I'm having trouble determining from the RM whether this is
|> true.
|> 
|>     generic
|>        type T is range <>;
|>        with function "*" (Left, Right : T) return T is <>;
|>     package GP is
|> 
|>        function Predefined_Mult (Left, Right : T) return T renames "*";
|> 
|>     end GP;
|> 
|> Now, it seems that Predefined_Mult will rename the user-defined "*"
|> (to do modular arithmetic or whatever) instead of the predefined "*".
|> Is this correct?  Please help.

Yes, it is correct. You can work it around this way.

I think the problem is not very severe when applied to the "*" operator.
One can still argue that, for numeric types, it is a good thing to have
the predefined view within generics.

I picked the "*" operator simply to make the example legal Ada 83, but
the point I really wanted to show is that it becomes very bad when applied
to the "=" operator, as in the following example:

package P is

   type T is private;

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

   ...

end P;

If you redefine "=" for T, you really don't want it to re-emerge inside
generics that you instantiate with P.T as a formal parameter. The
following example shows how bad this can be:

package V_String is

   type Text (Max_Length : Natural) is private;

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

private

   type Text (Max_Length : Natural) is
      record
         current_Length : Natural := 0;
         value : string(1 .. Max_Length);
      end record;

end;

Predefined equality on type Text is erroneous because in most cases it
will compare non-initialized components of Text.Value (I know, erroneous
has changed in Ada 9X). So, you really don't want the predefined version
of "=" to re-emerge inside generics.

--
Mats Weber
e-mail: weber@lglsun.epfl.ch

             reply	other threads:[~1993-09-14 19:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-09-14 19:53 cis.ohio-state.edu!math.ohio-state.edu!darwin.sura.net!spool.mu.edu!agate [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-09-17 10:12 Ada 9X: Eliminating the re-emergence of predefined operations cis.ohio-state.edu!math.ohio-state.edu!darwin.sura.net!news.dfn.de!scsing.switch.ch!epflnews!disuns2.epfl.ch!lglsun!madmats
1993-09-16 21:49 Tucker Taft
1993-09-14  3:15 cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!agate!dog.e
replies disabled

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