From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 14 Sep 93 19:53:07 GMT From: cis.ohio-state.edu!math.ohio-state.edu!darwin.sura.net!spool.mu.edu!agate !doc.ic.ac.uk!warwick!zaphod.crihan.fr!univ-lyon1.fr!scsing.switch.ch!epflnews! disuns2.epfl.ch!lglsun!madmats@ucbvax (Mats Weber) Subject: Re: Ada 9X: Eliminating the re-emergence of predefined operations Message-ID: <1993Sep14.212549@lglsun.epfl.ch> List-Id: In article , 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