2019-09-21 14:59:48 -07:00
|
|
|
// Test a PascaLIGO function which takes another PascaLIGO function as an argument
|
2019-05-12 20:56:22 +00:00
|
|
|
function foobar (const i : int) : int is
|
2020-01-24 14:35:15 +01:00
|
|
|
begin
|
|
|
|
function foo (const i : int) : int is i;
|
|
|
|
function bar (const f : int -> int) : int is f (i);
|
|
|
|
end with bar (foo);
|
2019-09-27 17:31:38 +02:00
|
|
|
|
|
|
|
// higher order function with more than one argument
|
2020-01-24 14:35:15 +01:00
|
|
|
function higher2(const i : int; const f : int -> int): int is
|
|
|
|
begin
|
|
|
|
const ii: int = f (i)
|
|
|
|
end with ii
|
2019-09-27 17:31:38 +02:00
|
|
|
|
|
|
|
function foobar2 (const i : int) : int is
|
2020-01-24 14:35:15 +01:00
|
|
|
begin
|
|
|
|
function foo2 (const i : int) : int is i
|
|
|
|
end with higher2 (i,foo2)
|
2019-10-02 17:28:11 +02:00
|
|
|
|
2019-10-17 17:18:10 +02:00
|
|
|
const a : int = 0;
|
2020-01-24 14:35:15 +01:00
|
|
|
|
2019-10-17 17:18:10 +02:00
|
|
|
function foobar3 (const i : int) : int is
|
2020-01-24 14:35:15 +01:00
|
|
|
begin
|
|
|
|
function foo2 (const i : int) : int is a+i
|
|
|
|
end with higher2 (i,foo2)
|
2019-10-03 15:36:06 +02:00
|
|
|
|
2020-01-24 14:35:15 +01:00
|
|
|
function f (const i : int) : int is i
|
2019-10-03 15:36:06 +02:00
|
|
|
|
2020-01-24 14:35:15 +01:00
|
|
|
function g (const i : int) : int is f (i)
|
2019-10-03 15:36:06 +02:00
|
|
|
|
2020-01-24 14:35:15 +01:00
|
|
|
function foobar4 (const i : int) : int is g (g (i))
|
2019-10-17 17:33:29 +02:00
|
|
|
|
2020-01-24 14:35:15 +01:00
|
|
|
function higher3(const i : int; const f : int -> int; const g : int -> int)
|
|
|
|
: int is
|
|
|
|
begin
|
|
|
|
const ii : int = f(g(i))
|
|
|
|
end with ii
|
2019-10-17 17:33:29 +02:00
|
|
|
|
|
|
|
function foobar5 (const i : int) : int is
|
2020-01-24 14:35:15 +01:00
|
|
|
begin
|
2019-11-18 16:10:48 +01:00
|
|
|
const a : int = 0;
|
2020-01-24 14:35:15 +01:00
|
|
|
function foo (const i : int) : int is a+i;
|
|
|
|
function goo (const i : int) : int is foo (i)
|
|
|
|
end with higher3(i,foo,goo)
|
2019-12-06 19:42:41 +01:00
|
|
|
|
2020-01-24 14:35:15 +01:00
|
|
|
function foobar6 (const i : int) : int -> int is f
|