From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: overloading predefined operators Date: Fri, 24 Jun 2022 12:47:10 +0200 Organization: A noiseless patient Spider Message-ID: References: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 24 Jun 2022 10:47:11 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="7c8f46217bcc95c4aaa9ec976d5d557c"; logging-data="31623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wPYd5T0NNN3RP0w3BVw3c2MnhJXv5VQM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Cancel-Lock: sha1:oEvt9ReHKe6FzTf3LfV3ZFQsbNA= In-Reply-To: <1fabca7a-e3f0-41bb-9b51-9eabde85e800n@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:64028 List-Id: On 2022-06-24 10:10, L. B. wrote: > > type my_float is new float; > > function "=" (left, right : in my_float) return boolean is begin > .... > end "=" > > a, b : my_float; > > a := 0.01 > b := 0.009; > > -- For some reasons I still need access to the overloaded original "=" function: > if a = b then -- shall use the original "=" > null; > end if; > > What can I do ? With a derived type like this, you can convert back to the parent type: if Float (A) = Float (B) then With a completely new type, you can only name one of the operations "=". You have to decide which one you want to call "=", and which one you want to call something else, like Equal. So, for type Real is digits 7; you can either call your new operation Equal function Equal (Left : in Real; Right : in Real) return Boolean; which leave "=" for the predefined operation, or you can rename the predefined operation to Equal as Kazakov has described function Equal (Left : in Real; Right : in Real) return Boolean renames "="; function "=" (Left : in Real; Right : in Real) return Boolean; -- Jeff Carter "[I]t is foolish to polish a program beyond the point of diminishing returns, but most programmers do too little revision; they are satisfied too early." Elements of Programming Style 189