From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8ffd9ca0013db6a7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-11-01 10:15:16 PST Path: supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!freenix!oleane.net!oleane!news-raspail.gip.net!news.gsl.net!gip.net!netnews.globalip.ch!news.vtx.ch!not-for-mail From: Mats Weber Newsgroups: comp.lang.ada Subject: Re: Redefined "=" = generic disaster? Date: Wed, 01 Nov 2000 18:47:13 +0100 Organization: VTX Services SA Message-ID: <3A005722.7E0BC50@mail.com> References: <39F13ED9.1EE@li.net> <39F1C092.87D4135E@acm.org> <39F1F686.26B5@li.net> <8tecab$epm$1@nnrp1.deja.com> <39FCEFAD.56BE85B1@ix.netcom.com> <8tkfme$v8a$1@nnrp1.deja.com> <39FE3C35.64CBB3C7@ix.netcom.com> <8tn7s1$9gp$1@nnrp1.deja.com> Reply-To: matsw@mail.com NNTP-Posting-Host: lsne-cable-2-p08.vtxnet.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.76 (Macintosh; U; PPC) X-Accept-Language: en,pdf Xref: supernews.google.com comp.lang.ada:1688 Date: 2000-11-01T18:47:13+01:00 List-Id: Robert Dewar wrote: > [...] > I still don't get it, the original claim was that there was > something special about "=" that made things particularly > awkward. > [...] I first wanted to shut up on this issue when I saw it reemerge. But I can't tell people to go to deja.com and search for it because searches for postings prior to May 15, 1999, are temporarily unavailable. I think there really is a problem with the reemergence of predefined operations within generics, and that problem has been acknowleged by the Ada 95 design team: draft versions of the 9X reference manual had rules removing the reemergence problem, but later these rules were removed in the final Ada 95 RM. IMO, this was a mistake. Anyway here is an example program that illustrates the problem (see code at end of message). The programmer defines the type V_String.T. Seeing that predefined equality will not work on that type, for obvious reasons, he redefines "=", thinking predefined equality is gone for good. Then he uses his type to instantiate a generic. Inside the generic, "=" is used. But unfortunately, it is not the redefined version of "=", but the predefined one that does not work. Now if we change the full definition of type T by removing the comment before "tagged", we get the expected result inside the generic. I.e. for tagged types, the reemergence problem does not exist. In this example, the generic is very simple for illustration purposes. But in a real program, P could be a package implementing an associative table for instance. In that case, the consequence is that the same key in the table can be inserted twice, and that existing keys in a table will not be found. There are other situations in which predefined equality reemerges. If we define a record type type R is record C : V_String.T; end record; then "=" on R will use predefined "=" on V_String.T, except if V_String.T is tagged. The reemergence problem on "=" did not exist in Ada 83 because you could only redefine "=" for limited private types (there is a contorted but still legal way that allows redefinition of "=" for a non limited type in Ada 83, but it was clearly not intended by the language designers IMO). I have discussed the reemergence problem in my PhD thesis, see http://lglwww.epfl.ch/Team/MW/Ada-Extensions/Ada-Extensions.html#RTFToC97 if you want to read more about it. I don't know if the Ada 9X drafts with the rules to eliminate it are still online somewhere. -- with Text_IO; use Text_IO; procedure Reemergence_Should_Have_Been_Removed_In_Ada_95 is package V_String is type T is private; function "=" (Left, Right : T) return Boolean; procedure Assign (Object : out T; Value : in String); private type T is -- tagged record Length : Natural; Value : String(1 .. 100); end record; end V_String; package body V_String is function "=" (Left, Right : T) return Boolean is begin return Left.Value(1 .. Left.Length) = Right.Value(1 .. Right.Length); end; procedure Assign (Object : out T; Value : in String) is begin Object.Length := Value'Length; Object.Value(1 .. Value'Length) := Value; end; end V_String; generic type T is private; package P is function Compare (X, Y : T) return Boolean; end P; package body P is function Compare (X, Y : T) return Boolean is begin return X = Y; end; end P; package PV is new P(V_String.T); X, Y : V_String.T; use V_String; begin Assign(X, "abcd"); Assign(Y, "abc"); Assign(X, "abc"); if X = Y then Put_Line("X = Y outside P"); else Put_Line("X /= Y outside P"); end if; if PV.Compare(X, Y) then Put_Line("X = Y inside P"); else Put_Line("X /= Y inside P"); end if; end;