Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,56 +0,0 @@
|
|||
with Ada.Float_Text_IO,
|
||||
Ada.Integer_Text_IO,
|
||||
Ada.Text_IO,
|
||||
Ada.Numerics.Elementary_Functions;
|
||||
|
||||
procedure First_Class_Functions is
|
||||
use Ada.Float_Text_IO,
|
||||
Ada.Integer_Text_IO,
|
||||
Ada.Text_IO,
|
||||
Ada.Numerics.Elementary_Functions;
|
||||
|
||||
function Sqr (X : Float) return Float is
|
||||
begin
|
||||
return X ** 2;
|
||||
end Sqr;
|
||||
|
||||
type A_Function is access function (X : Float) return Float;
|
||||
|
||||
generic
|
||||
F, G : A_Function;
|
||||
function Compose (X : Float) return Float;
|
||||
|
||||
function Compose (X : Float) return Float is
|
||||
begin
|
||||
return F (G (X));
|
||||
end Compose;
|
||||
|
||||
Functions : array (Positive range <>) of A_Function := (Sin'Access,
|
||||
Cos'Access,
|
||||
Sqr'Access);
|
||||
Inverses : array (Positive range <>) of A_Function := (Arcsin'Access,
|
||||
Arccos'Access,
|
||||
Sqrt'Access);
|
||||
begin
|
||||
for I in Functions'Range loop
|
||||
declare
|
||||
function Identity is new Compose (Functions (I), Inverses (I));
|
||||
Test_Value : Float := 0.5;
|
||||
Result : Float;
|
||||
begin
|
||||
Result := Identity (Test_Value);
|
||||
|
||||
if Result = Test_Value then
|
||||
Put ("Example ");
|
||||
Put (I, Width => 0);
|
||||
Put_Line (" is perfect for the given test value.");
|
||||
else
|
||||
Put ("Example ");
|
||||
Put (I, Width => 0);
|
||||
Put (" is off by");
|
||||
Put (abs (Result - Test_Value));
|
||||
Put_Line (" for the given test value.");
|
||||
end if;
|
||||
end;
|
||||
end loop;
|
||||
end First_Class_Functions;
|
||||
|
|
@ -9,7 +9,7 @@ extension op
|
|||
= f(g(self));
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var fs := new object[]{ mssgconst sin<mathOp>[1], mssgconst cos<mathOp>[1], (x => power(x, 3.0r)) };
|
||||
var gs := new object[]{ mssgconst arcsin<mathOp>[1], mssgconst arccos<mathOp>[1], (x => power(x, 1.0r / 3)) };
|
||||
|
|
|
|||
|
|
@ -2,4 +2,3 @@ a: [sin, cos, lambda([x], x^3)]$
|
|||
b: [asin, acos, lambda([x], x^(1/3))]$
|
||||
compose(f, g) := buildq([f, g], lambda([x], f(g(x))))$
|
||||
map(lambda([fun], fun(x)), map(compose, a, b));
|
||||
[x, x, x]
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
REBOL [
|
||||
Title: "First Class Functions"
|
||||
URL: http://rosettacode.org/wiki/First-class_functions
|
||||
]
|
||||
|
||||
; Functions "foo" and "bar" are used to prove that composition
|
||||
; actually took place by attaching their signatures to the result.
|
||||
|
||||
foo: func [x][reform ["foo:" x]]
|
||||
bar: func [x][reform ["bar:" x]]
|
||||
|
||||
cube: func [x][x * x * x]
|
||||
croot: func [x][power x 1 / 3]
|
||||
|
||||
; "compose" means something else in REBOL, so I "fashion" an alternative.
|
||||
|
||||
fashion: func [f1 f2][
|
||||
do compose/deep [func [x][(:f1) (:f2) x]]]
|
||||
|
||||
A: [foo sine cosine cube]
|
||||
B: [bar arcsine arccosine croot]
|
||||
|
||||
while [not tail? A][
|
||||
fn: fashion get A/1 get B/1
|
||||
source fn ; Prove that functions actually got composed.
|
||||
print [fn 0.5 crlf]
|
||||
|
||||
A: next A B: next B ; Advance to next pair.
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue