From: nobody@REPLAY.COM (Anonymous)
Subject: Re: How can I qualify the predefined logical operations
Date: 1998/07/16
Date: 1998-07-16T00:00:00+00:00 [thread overview]
Message-ID: <199807161400.QAA29443@basement.replay.com> (raw)
In-Reply-To: 6okcnl$n93$1@nnrp1.dejanews.com
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/
next prev parent reply other threads:[~1998-07-16 0:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-07-16 0:00 How can I qualify the predefined logical operations hoyngj
1998-07-16 0:00 ` Anonymous [this message]
1998-07-16 0:00 ` dennison
1998-07-16 0:00 ` Tucker Taft
1998-07-16 0:00 ` dennison
1998-07-16 0:00 ` hoyngj
1998-07-17 0:00 ` Robert Dewar
1998-07-17 0:00 ` Andreas Kalla
1998-07-19 0:00 ` Mats Weber
1998-07-25 0:00 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox