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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1fee5782cd952ed7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1993-03-17 20:39:24 PST Newsgroups: comp.lang.ada Path: sparky!uunet!gatech!howland.reston.ans.net!usc!news.cerf.net!shrike.irvine.com!adam From: adam@irvine.com (Adam Beneschan) Subject: Re: How do I avoid 'use' in this case? In-Reply-To: eriks@lin.foa.se's message of Thu, 11 Mar 1993 18:20:21 GMT References: <1993Mar11.163904.18135@fcom.cc.utah.edu> <1993Mar11.182021.1129@lin.foa.se> Sender: usenet@irvine.com (News Administration) Organization: Irvine Compiler Corp., Irvine, California, USA Date: Thu, 18 Mar 1993 03:02:23 GMT Message-ID: Date: 1993-03-18T03:02:23+00:00 List-Id: In article <1993Mar11.182021.1129@lin.foa.se> eriks@lin.foa.se (Erik Svensson FOA2) writes: > Use rename instead. > Like this: > > function "/="(A,B:Foo) return boolean renames field_def."/="; > > You could do field_def. "/="from the beginning, but that`s not so > convinient. Wrong. You cannot rename the "/=" operator. What you need to do is rename the "=" operator: function "="(A,B:Foo) return boolean renames field_def."="; and then "/=" will be defined automatically. /= is the only operator that cannot be renamed explicitly. By the way, the original post asked how to use operators such as /= without using the USE clause. Several responses have suggested putting a RENAMES in the using package to make the operator visible. While this is correct, if a common package P is with'ed by lots of other packages Q1, Q2, etc., putting a RENAMES clause for every operator in every using package Q1, Q2, ..., is quite tedious. There's a better way around this, in my opinion. Put the RENAMES in a subpackage of P, like this: package P is type some_type_1 is record ... end record; type some_type_2 is (val1, val2, val3, ...); package OPERATORS is function "=" (left, right : some_type_1) return boolean renames P."="; function "=" (left, right : some_type_2) return boolean renames P."="; function "<" (left, right : some_type_2) return boolean renames P."<"; function "<=" (left, right : some_type_2) return boolean renames P."<="; ... same for ">", ">=" end OPERATORS; end P; Now, in packages Q1, Q2, etc., you can make all the operators visible very simply: with P; package Q1 is use P.OPERATORS; procedure PR (x, y : P.some_type_2) is begin if x = y then . . . . . . . This does use the "use" statement, so if your Ada compiler has an automatic preprocessor that deletes your source file if it sees the word "use" :-), this solution won't work. However, in environments where rules like this aren't carved in stone, I think this is a great solution. Although it uses "use", it uses it in a restricted way that doesn't make the whole world visible, and so IMHO it doesn't have the problems that are usually associated with "use". -- Adam