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,f9cd205deb0d77f2 X-Google-Attributes: gid103376,public From: nobody@REPLAY.COM (Anonymous) Subject: Re: How can I qualify the predefined logical operations Date: 1998/07/16 Message-ID: <199807161400.QAA29443@basement.replay.com>#1/1 X-Deja-AN: 372021447 Content-Transfer-Encoding: 7bit References: <6okcnl$n93$1@nnrp1.dejanews.com> Organization: Replay Associates, L.L.P. Mail-To-News-Contact: postmaster@nym.alias.net X-001: Replay may or may not approve of the content of this posting X-002: Report misuse of this automated service to X-URL: http://www.replay.com/remailer/ Content-Type: text/plain; charset=us-ascii Newsgroups: comp.lang.ada Date: 1998-07-16T00:00:00+00:00 List-Id: On Thu, 16 Jul 1998 08:13:42 GMT, hoyngj@my-dejanews.com wrote: > 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. > ... This is a well-known situation. Maybe we should put it in the FAQ (pause while I check the FAQ)? OK, I just glanced at the FAQs at www.adahome.com and see nothing on this subject, so I'll continue. The problem is that predefined "and" for Private_Type is not defined in Standard, but in Some_Package by the full declaration of Private_Type, where it is already hidden by the explicit declaration of "and". There are two common solutions to this problem, neither of which is entirely acceptable to everyone. The first is to wrap your type in a record: type Boolean_List is array (Natural range <>) of Boolean; type Private_Type is record Value : Boolean_List (0 .. 1_023) := (others => False); end record; This approach has the advantage of allowing you to ensure that all objects of the type are initialized, which is why I use it frequently. Your function would be function "and" (Left : Private_Type; Right : Private_Type) return Private_Type is begin -- "and" return Private_Type'(Value => Left.Value and Right.Value); end "and"; although some degenerates would write return (Left.Value and Right.Value); The second solution is to make your type a derived type: type Boolean_List is array (Natural range 0 .. 1_023) of Boolean; type Private_Type is new Boolean_List; Now "and" is only redefined for Private_Type, not for Boolean_List, so you can write function "and" (Left : Private_Type; Right : Private_Type) return Private_Type is begin -- "and" return Private_Type (Boolean_List (Left) and Boolean_List (Right) ); end "and"; Good luck! Jeff Carter PGP:1024/440FBE21 My real e-mail address: ( carter @ innocon . com ) "Your mother was a hamster and your father smelt of elderberries." Monty Python & the Holy Grail Posted with Spam Hater - see http://www.compulink.co.uk/~net-services/spam/