comp.lang.ada
 help / color / mirror / Atom feed
* Generic child unit renaiming
@ 1999-04-22  0:00 noiraud
  1999-04-25  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 2+ messages in thread
From: noiraud @ 1999-04-22  0:00 UTC (permalink / raw)



I would like to rename Math_Extension an extension of the
generic package Ada.Numerics.Generic_Elementary_Functions.

Thus, I created a generic child unit :

   generic
   package Ada.Numerics.Generic_Elementary_Functions.Extensions is

      function Log10 (X : Float_Type'Base) return Float_Type'Base;

      function Asin  (X : Float_Type'Base) return Float_Type'Base
         renames Arcsin;

   end Ada.Numerics.Generic_Elementary_Functions.Extensions;

and I tried the following renaming :

   with Ada.Numerics.Generic_Elementary_Functions.Extensions;

   generic package Math_Extension renames
      Ada.Numerics.Generic_Elementary_Functions.Extensions;

The GNAT compiler refused it :

   >>> invalid prefix in selected component "Generic_Elementary_Functions".

I read that a child of a generic parent can only be renamed if the renaming
occurs inside the declarative region of its parent unit, but I can't do it
because Generic_Elementary_Functions belongs to the predefined library.

An other solution could be to implement in Math_Extension package using an
instanciation of Generic_Elementary_Functions :

   generic
      type Real is digits <>;
   package Math_Extension is

      package Math is new Ada.Numerics.Generic_Elementary_Functions (Real);

      function Sqrt (X : Real'Base) return Real'Base renames Math.Sqrt;

      ...

      function Log10 (X : Real'Base) return Real'Base;

      function Asin  (X : Real'Base) return Real'Base
         renames Math.Arcsin;

   end Math_Extension;

but instanciate Math_Extension has a performance cost because of the double
instanciation.

Could anyone help me ?

Thanks in advance.





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Generic child unit renaiming
  1999-04-22  0:00 Generic child unit renaiming noiraud
@ 1999-04-25  0:00 ` Matthew Heaney
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Heaney @ 1999-04-25  0:00 UTC (permalink / raw)


noiraud@cenaath.cena.dgac.fr writes:

> I would like to rename Math_Extension an extension of the
> generic package Ada.Numerics.Generic_Elementary_Functions.

Don't do this.

> An other solution could be to implement in Math_Extension package using an
> instanciation of Generic_Elementary_Functions :
> 
>    generic
>       type Real is digits <>;
>    package Math_Extension is
> 
>       package Math is new Ada.Numerics.Generic_Elementary_Functions (Real);
> 
>       function Sqrt (X : Real'Base) return Real'Base renames Math.Sqrt;
> 
>       ...
> 
>       function Log10 (X : Real'Base) return Real'Base;
> 
>       function Asin  (X : Real'Base) return Real'Base
>          renames Math.Arcsin;
> 
>    end Math_Extension;
> 
> but instanciate Math_Extension has a performance cost because of the double
> instanciation.


I don't know what you mean by "performance cost," but you can always
import the instantiation as a generic formal package:

with Ada.Numerics.Generic_Elementary_Functions; use Ada.Numerics;
generic
  type Real is digits <>;
  with package Math is new Generic_Elementary_Functions (Real);
package Math_Extension is ...;







^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-04-25  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-22  0:00 Generic child unit renaiming noiraud
1999-04-25  0:00 ` Matthew Heaney

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