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, T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f9cd205deb0d77f2 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: How can I qualify the predefined logical operations Date: 1998/07/25 Message-ID: #1/1 X-Deja-AN: 374827175 Sender: matt@mheaney.ni.net References: <6okcnl$n93$1@nnrp1.dejanews.com> NNTP-Posting-Date: Sat, 25 Jul 1998 08:48:24 PDT Newsgroups: comp.lang.ada Date: 1998-07-25T00:00:00+00:00 List-Id: hoyngj@my-dejanews.com writes: > I have the following problem, when trying to implement a function "and". > > package Some_Package is > type Private_Type is private; > function "And" (Left, Right: Private_Type) return Private_Type ; > private > type Private_Type is array (0 .. 1023) of Boolean; > end Some_Package; > > > -- I want to implement Some_Package."And" using the predefined logical > -- operation "And" for any one-dimensional array type whose components > -- are of a boolean type. > package body Some_Package is > function "And" (Left, Right: Private_Type) return Private_Type is > begin > return Left and Right; -- ERROR: AND is here Some_Package."AND", > -- endless recursive > end "and"; > end Some_Package; I like to do this: private type Rep is array (0 .. 1023) of Boolean; type Private_Type is new Private_Type_Rep; end Some_Package; function "and" (L, R : Private_Type) return Private_Type is begin return Rep (L) and Rep (R); end; The problem you're having is that the public and private views of the type share a namespace. This is sometimes a pain, but you can get around it simply by just declaring separate types for the public and private views, and explicitly converting between them in the body. Another technique is to implement the full view of the type as a record: private type Boolean_Array is array (0 .. 1023) of Boolean; type Private_Type is record Values : Boolean_Array; end record; end; function "and" (L, R : Private_Type) return Private_Type is begin return L.Values and R.Values; end; This is another way to create separate namespaces for the public and private views of a type. > To fix the error in the implementation above, I need to qualify the > predefined "And" operation: > > > package body Some_Package is > function "And" (Left, Right: Private_Type) return Private_Type is > begin > return Standard."And" (Left, Right); -- ERROR: not possible > end "and"; > end Some_Package; > > How is it possible to qualify the predefined logical operations to > distinguish between Some_Package."and" and the predefined "and"? No. The operator "and" is implicitly declared immediately after the declaration of the full view of the type. As if you did this: private type Private_Type is array (0 .. 1023) of Boolean; function "and" (L, R : Private_Type) return Boolean; end; In times like this (operations for the public type have the same signiture as predefined operations of the private type), it's best to use either type derivation or a record type to implement the full view of the type.