User:Coderjoe/Sandbox2: Difference between revisions
Content added Content deleted
(begin testing for busted geshi language) |
No edit summary |
||
Line 1: | Line 1: | ||
⚫ | |||
<lang ActionScript>function compose(f:Function, g:Function):Function { |
|||
with Ada.Text_IO; |
|||
return function(x:Number) {return f(g(x));}; |
|||
with Ada.Numerics.Generic_Elementary_Functions; |
|||
} |
|||
procedure Program is |
|||
var functions:Array = [Math.cos, Math.tan, function(x:Number){return x*x;}]; |
|||
generic |
|||
var inverse:Array = [Math.acos, Math.atan, function(x:Number){return Math.sqrt(x);}]; |
|||
type Number_Type is private; |
|||
with function F(X : Number_Type) return Number_Type; |
|||
with function G(X : Number_Type) return Number_Type; |
|||
function Compose(X : Number_Type) return Number_Type; |
|||
function Compose(X : Number_Type) return Number_Type is begin return F(G(X)); end; |
|||
type Function_Type is access function(X : Float) return Float; |
|||
function sqr(X : Float) return Float is begin return X * X; end; |
|||
package Math is new Ada.Numerics.Generic_Elementary_Functions(Float); |
|||
type Function_List is array(Natural range <>) of Function_Type; |
|||
functions : Function_List := (Math.sin'Access, Math.cos'Access, Program.sqr'Access); |
|||
inverts : Function_List of Function_Type := (Math.arcsin'Access, Math.arccos'Access, Math.sqrt'Access); |
|||
begin |
|||
for i in functions'Range loop |
|||
declare |
|||
function C is new Compose(Float, functions(i).all, inverts(i).all); |
|||
begin |
|||
Ada.Text_IO.Put_Line(Float'Image(C(0.5))); |
|||
end; |
|||
end loop; |
|||
end Program; |
|||
</lang> |
|||
function test() { |
|||
for (var i:uint = 0; i < functions.length; i++) { |
|||
trace(compose(functions[i], inverse[i])(0.5)); |
|||
} |
|||
⚫ |
Revision as of 20:34, 16 July 2011
<lang Ada> with Ada.Text_IO; with Ada.Numerics.Generic_Elementary_Functions; procedure Program is
generic type Number_Type is private; with function F(X : Number_Type) return Number_Type; with function G(X : Number_Type) return Number_Type; function Compose(X : Number_Type) return Number_Type; function Compose(X : Number_Type) return Number_Type is begin return F(G(X)); end; type Function_Type is access function(X : Float) return Float; function sqr(X : Float) return Float is begin return X * X; end; package Math is new Ada.Numerics.Generic_Elementary_Functions(Float); type Function_List is array(Natural range <>) of Function_Type; functions : Function_List := (Math.sin'Access, Math.cos'Access, Program.sqr'Access); inverts : Function_List of Function_Type := (Math.arcsin'Access, Math.arccos'Access, Math.sqrt'Access);
begin
for i in functions'Range loop declare
function C is new Compose(Float, functions(i).all, inverts(i).all);
begin
Ada.Text_IO.Put_Line(Float'Image(C(0.5)));
end; end loop;
end Program;
</lang>