-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.barrett
executable file
·59 lines (51 loc) · 1.08 KB
/
lambda.barrett
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var
X, F, S;
function EvalFunc(func, param);
begin
func(param);
end;
function GetFunc;
begin
Result :=
lambda(x);
begin
WriteLn(x * x);
end;
;
end;
function StringAppender(str);
begin
Result :=
lambda(x);
begin
WriteLn(x + str);
end;
;
end;
begin
{ Assign a function to variable X before calling it }
X :=
lambda;
begin
WriteLn("Hello World");
end;
;
X;
{ Call EvalFunc using a lambda as the first argument
and the string "Hello World" as the second argument }
EvalFunc(
lambda(str);
begin
WriteLn(str);
end;
, "Hello World");
{ Assign function returned by GetFunc to variable and call it }
F := GetFunc;
F(3);
F(5);
{ Assign function with different parameters applied }
F := StringAppender(";");
S := StringAppender(".");
F("Hello"); { Prints "Hello;" }
S("Hello"); { Prints "Hello." }
end;