Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Function-composition/Ada/function-composition-1.ada
Normal file
13
Task/Function-composition/Ada/function-composition-1.ada
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
generic
|
||||
type Argument is private;
|
||||
package Functions is
|
||||
type Primitive_Operation is not null
|
||||
access function (Value : Argument) return Argument;
|
||||
type Func (<>) is private;
|
||||
function "*" (Left : Func; Right : Argument) return Argument;
|
||||
function "*" (Left : Func; Right : Primitive_Operation) return Func;
|
||||
function "*" (Left, Right : Primitive_Operation) return Func;
|
||||
function "*" (Left, Right : Func) return Func;
|
||||
private
|
||||
type Func is array (Positive range <>) of Primitive_Operation;
|
||||
end Functions;
|
||||
25
Task/Function-composition/Ada/function-composition-2.ada
Normal file
25
Task/Function-composition/Ada/function-composition-2.ada
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package body Functions is
|
||||
function "*" (Left : Func; Right : Argument) return Argument is
|
||||
Result : Argument := Right;
|
||||
begin
|
||||
for I in reverse Left'Range loop
|
||||
Result := Left (I) (Result);
|
||||
end loop;
|
||||
return Result;
|
||||
end "*";
|
||||
|
||||
function "*" (Left, Right : Func) return Func is
|
||||
begin
|
||||
return Left & Right;
|
||||
end "*";
|
||||
|
||||
function "*" (Left : Func; Right : Primitive_Operation) return Func is
|
||||
begin
|
||||
return Left & (1 => Right);
|
||||
end "*";
|
||||
|
||||
function "*" (Left, Right : Primitive_Operation) return Func is
|
||||
begin
|
||||
return (Left, Right);
|
||||
end "*";
|
||||
end Functions;
|
||||
12
Task/Function-composition/Ada/function-composition-3.ada
Normal file
12
Task/Function-composition/Ada/function-composition-3.ada
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Functions;
|
||||
|
||||
procedure Test_Compose is
|
||||
package Float_Functions is new Functions (Float);
|
||||
use Float_Functions;
|
||||
|
||||
Sin_Arcsin : Func := Sin'Access * Arcsin'Access;
|
||||
begin
|
||||
Put_Line (Float'Image (Sin_Arcsin * 0.5));
|
||||
end Test_Compose;
|
||||
Loading…
Add table
Add a link
Reference in a new issue