comp.lang.ada
 help / color / mirror / Atom feed
From: Jeff Carter <carter@spam.innocon.com>
Subject: Re: Tagged Types and Generics
Date: 1997/04/24
Date: 1997-04-24T00:00:00+00:00	[thread overview]
Message-ID: <335F67FF.41C67EA6@spam.innocon.com> (raw)
In-Reply-To: 3.0.32.19970421225247.007129f4@mail.4dcomm.com


Robert C. Leif, Ph.D. wrote:
>...
>   generic
> 
>       type Num_Or_Denom is delta <> digits <>;
>       type Ratio is delta <> digits <>;
> 
>       package Dec_Divide is
> 
>       type Num_Or_Denoms is abstract tagged private;
>      --This the start of the class
> 
>     Function Ratio_Test(Numerator : in Num_Or_Denoms'Class;
>                         Denominator : in Num_Or_Denoms'Class)
>                         return Ratio;
> Private
>       type Num_Or_Denoms is abstract tagged
>             record
>             The_Num_Or_Denom : Num_Or_Denom;
>             Num_Or_Denom_Scale: Integer := Num_Or_Denom'Scale;
>             Num_Or_Denom_digits: Integer := Num_Or_Denom'digits ;
>                          end record;
>    end Dec_Divide;

I don't see any point to this. All objects in Num_Or_Denoms'Class have
the same type for component The_Num_Or_Denom, and the same default
values for components Num_Or_Denom_Scale and Num_Or_Denom_Digits.

>     46.          Procedure Divide is new Ada.Decimal.Divide
>     47.            (Dividend_type => Gen_Numerator,
>     48.             Divisor_Type  => Gen_Denominator,
>     49.             Quotient_Type => Ratio,
>     50.             Remainder_Type => Ratio);
>     51.
>     52.          Use Divide;
>                      |
>         >>> "Divide" is not a usable package

This instantiation creates a procedure. You can't "use" a procedure.

If you could do it, this would be the same as

   procedure Divide is new Ada.Decimal.Divide
      (Dividend_Type  => Num_Or_Denom,
       Divisor_Type   => Num_Or_Denom,
       Quotient_Type  => Ratio,
       Remainder_Type => Ratio);

unless you somehow changed the values of the components
Num_Or_Denom_Scale and Num_Or_Denom_Digits. Perhaps you had planned on a
way to do this, but it's not clear from your post.

Even if you change these values, the numbers you are dividing are still
of type Num_Or_Denom, and your result of type Ratio. You are simply
performing a conversion to another type, equivalent to:

   type Z is delta A digits B;
   type Y is delta C digits D;
   type X is delta E digits F;
   type W is delta G digits H;

   procedure Divide is new Ada.Decimal.Divide (Dividend_Type  => Y,
                                               Divisor_Type   => X,
                                               Quotient_Type  => W,
                                               Remainder_Type => W);

   Dend : Z;
   Sor  : Z;
   Quot : W;
   Rmdr : W;
   ...
   Divide (Dividend  => Y (Dend),
           Divisor   => X (Sor),
           Quotient  => Quot,
           Remainder => Rmdr);

Watch out for the auntie-spam return address.
-- 
Jeff Carter  ( carter @ innocon . com )  PGP:1024/440FBE21

"Now go away, or I shall taunt you a second time." Monty Python & the
Holy Grail




  reply	other threads:[~1997-04-24  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-21  0:00 Tagged Types and Generics Robert C. Leif, Ph.D.
1997-04-24  0:00 ` Jeff Carter [this message]
1997-04-25  0:00 ` Robert Dewar
1997-04-26  0:00   ` Tom Moran
1997-04-26  0:00   ` Matthew Heaney
1997-04-27  0:00   ` Nick Roberts
1997-04-28  0:00 ` Robert I. Eachus
1997-04-28  0:00   ` Tom Moran
  -- strict thread matches above, loose matches on Subject: below --
1997-04-26  0:00 Robert C. Leif, Ph.D.
1997-04-27  0:00 ` Robert Dewar
1997-05-02  0:00   ` Nick Roberts
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox