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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c3a7c1845ec5caf9 X-Google-Attributes: gid103376,public From: mab@dst1.wdl.loral.com (Mark A Biggar) Subject: Re: Equality operator overloading in ADA 83 Date: 1997/04/22 Message-ID: <5jiq7t$o35@wdl1.wdl.lmco.com>#1/1 X-Deja-AN: 236617713 References: <01bc4e9b$ac0e7fa0$72041dc2@lightning> <33602040.3178674@news.airmail.net> Organization: Loral Western Development Labs Newsgroups: comp.lang.ada Date: 1997-04-22T00:00:00+00:00 List-Id: In article <33602040.3178674@news.airmail.net> clines@delete_this.airmail.net (Kevin Cline) writes: >"Manuel Wenger" wrote: >>I've started doing some DecADA 83 programming at a technical engineering >>school ... and I've run into a problem that I was unable to solve (and my >>teacher didn't know any better either :-)) >>I've tried to overload the "=" operator for fractions in a package. It >>obviously doesn't work if the type isn't defined as "limited private", and >>I don't want that. As an alternative, I found out that I might as well do a >>renaming declaration, just by defining the type as "private" - so I've >>tried doing that as well, and then using the following to rename the equal >>sign: >>In other words, how do I tell my "equal" function to be an equality >>operator, authorized to be renamed into "="? HELP! :) >You can't. Period. Why? I don't know. Drove me crazy once. >Maybe some Ada-83 committee member will volunteer why it was >considered reasonable to redefine '<' and '>' but not '=' . Actually you can by cheating and using generics. define a genreics package looking something like: generic type FOO is limited private; with function EQ(L,R: FOO) return Boolean is <>; package MAKE_EQUALS is function "="(L,R: FOO) return Boolean; end MAKE_EQUALS; package body MAKE_EQUALS is function "="(L,R: FOO) return Boolean is body return EQ(L,R); end "='; end MAKE_EQUALS; now you can instantiate it as: package FAKE_IT is new MAKE_EQUALS(FOO => Your_Type, EQ => Your_Equals); Now FAKE_IT."=" is an equality operator of your type and can be freely renamed into what ever scope you want. -- Mark Biggar mab@wdl.lmco.com