comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Gordon <annihilan@gmail.com>
Subject: Understanding generic package functions
Date: Mon, 2 Nov 2015 16:45:15 -0800 (PST)
Date: 2015-11-02T16:45:15-08:00	[thread overview]
Message-ID: <cb181260-a5d3-4b5b-9a40-c925f7100b93@googlegroups.com> (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

             reply	other threads:[~2015-11-03  0:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03  0:45 Nick Gordon [this message]
2015-11-03  3:36 ` Understanding generic package functions 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
replies disabled

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