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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ebbca47c76670bb2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-31 15:48:00 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!ra.nrl.navy.mil!dca6-feed2.news.algx.net!allegiance!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Reemergence of predefined equality operator... Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Wed, 31 Jul 2002 22:47:43 GMT References: NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:27545 Date: 2002-07-31T22:47:43+00:00 List-Id: Dale Stanbrough writes: > I was demonstrating what i thought would be the reemergence of > the predefined equality operator by doing... > > type text is... (record with length & chars, like bounded string) > function "=" (a, b : text) return boolean; > > > and > > > generic > type element is private; > with function "=" (a, b : element) return boolean is <>; > package... > > and after instantiating the generic with type text it kept calling > the "=" defined for type text. > > I thought Ada (through a bad design decision) said that it should call > the predefined "=" opertor in this instance. Has this been changed, > or do have I misunderstood the problem? You've misunderstood the problem. ;-) Above, you passed in a formal "=" explicitly. The "is <>" means that the default is to pass in whatever "=" happens to be visible at the place of the instantiaation (and has the right profile types). That is probably the user-defined "=" that you wanted. In that case, the "problem" does not occur. The "problem" is when you leave out the explicit ``with function "="...''. Then type "element" has a predefined "=" (because it's private, not limited private). In that case, the predefined "=" of the actual type "reemerges". In other words, if you instantiate with Element => T, and T has a primitive user-defined "=", the instance will call the predefined "=" rather than the user-defined one. If you wanted to drive a stake through the heart of the predefined "=" by declaring a user-defined "=", so that every time objects of type T are compared for equality it will call the user-defined "=", then you lose -- if you pass T to a generic or wrap T in a record, the predefined "=" reemerges (rises from the dead). For "=", this seems "obviously" wrong. But as I pointed out elsewhere, the situation for other operators (eg, "mod"), is not so obvious. Even if the language were changed, or even if Text_IO.Integer_IO took "mod" as an "is <>" parameter as above, it's not clear (to me) what the right answer is. - Bob