comp.lang.ada
 help / color / mirror / Atom feed
* Understanding generic package functions
@ 2015-11-03  0:45 Nick Gordon
  2015-11-03  3:36 ` Jeffrey R. Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nick Gordon @ 2015-11-03  0:45 UTC (permalink / raw)


Okay, basically I'm writing a demo of Ada for a class, and I'm trying to showcase Ada's math functions. This is the code:

   function Recoded_Exp(Power: in Float) return Float is -- Base e
      use Ada.Numerics.Generic_Elementary_Functions;
      use Ada.Numerics;
      ExpResult : Float;
   begin
      ExpResult := e ** Power;
      return ExpResult;
   end Recoded_Exp;

As you can see, what I'm trying to accomplish is confine the Float version of the "**" operator to this function, and I can't seem to do that, as well as use Ada's language-defined e constant. I've tried this by declaring the whole name, i.e. "Ada.Numerics.e Ada.Numerics.Generic_Elementary_Functions."**" Power", as well without the quotes enclosing the asterisks. Neither worked.

I've seen something that suggests I have to instantiate the generic package, but I don't understand how. For reference, the suggested approach is here:

with Square;
with Matrices;
procedure Matrix_Example is
  function Square_Matrix is new Square
    (Element_T => Matrices.Matrix_T, "*" => Matrices.Product);
  A : Matrices.Matrix_T := Matrices.Identity;
begin
  A := Square_Matrix (A);
end Matrix_Example;

My thought is that I have to create a new instance of the Generic_Elementary_Functions package, but I'm not sure if that's correct, or how to do that. In general, I'm noticing that the learning curve for Ada is steep, and there are not terribly many "quick references" for the language.

Nick

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

end of thread, other threads:[~2015-11-03 17:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-03  0:45 Understanding generic package functions Nick Gordon
2015-11-03  3:36 ` Jeffrey R. Carter
2015-11-03  6:59 ` Randy Brukardt
2015-11-03  7:59   ` Nick Gordon
2015-11-03  9:15     ` briot.emmanuel
2015-11-03 17:27     ` Jeffrey R. Carter
2015-11-03  9:40 ` Stephen Leake

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