-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.pc
59 lines (48 loc) · 1.05 KB
/
test.pc
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
#lang polecat
(***** testing polecat language *****)
main() = (
println(m);
println("Testing Polecat Language\n" ^
"------------------------");
println("\nbignum:");
println(pow(2, 100));
println("\nrecursion, nested procedure:");
let ls = fibs(50) in (
println(ls);
println("\nlambda, higher order procedure:");
println(sum(ls))
)
)
m = let
a = 10
b = 20
in
(a + b) * a
pow(m, n) =
if n = 0 then 1
else m * pow(m, n - 1)
fibs(n) =
let
f(c, acc) =
if c > n then acc
else if c >= 2 then f(c + 1, first(acc) + second(acc) :: acc)
else f(c + 1, c :: acc)
in
reverse(f(0, []))
second(ls) = first(rest(ls))
reverse(ls) =
let
f(ls, acc) =
if empty(ls) then acc
else f(rest(ls), first(ls) :: acc)
in
f(ls, [])
fold(f, init, ls) =
let
g(acc, ls) =
if empty(ls) then acc
else g(f(first(ls), acc), rest(ls))
in
g(init, ls)
sum(ls) = fold(lambda (m, n) = m + n, 0, ls)
_ = main()