-
Notifications
You must be signed in to change notification settings - Fork 0
/
gc_test.lam
83 lines (65 loc) · 2.16 KB
/
gc_test.lam
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(\f b -> b f) (\f b -> b f)
\define ->
define (\x -> x) \id ->
define (\c x -> c) \const ->
define (\f -> (\x -> f (x x)) (\x -> f (x x)))
\fix ->
define (\x y -> x) \true ->
define (\x y -> y) \false ->
define (\b x y -> b y x) \not ->
define (\a b -> a b false) \and ->
define (\a b -> a true b) \or ->
define (\x y f -> f x y) \cons ->
define (\p -> p true) \car ->
define (\p -> p false) \cdr ->
define false \nil ->
define (\p -> p (\_ _ _ -> false) true) \isNil ->
define (\p -> not (isNil p)) \isPair ->
define (fix (\map f xs -> isNil xs nil (cons (f (car xs)) (map f (cdr xs)))))
\map ->
define (fix (\filter f xs -> isNil xs nil (f (car xs) (cons (car xs) (filter f (cdr xs)))
(filter f (cdr xs)))))
\filter ->
define (fix (\foldr step init xs ->
isNil xs init (step (car xs) (foldr step init (cdr xs)))))
\foldr ->
define (\f x -> x) \0 ->
define (\n f x -> f (n f x)) \succ ->
define (succ 0) \1 ->
define (succ 1) \2 ->
define (succ 2) \3 ->
define (succ 3) \4 ->
define (succ 4) \5 ->
define (succ 5) \6 ->
define (succ 6) \7 ->
define (succ 7) \8 ->
define (succ 8) \9 ->
define (succ 9) \10 ->
define (\n f x -> n (\h g -> g (h f)) (\g -> x) id)
\prec ->
define (\n m -> n succ m) \+ ->
define (\n m -> m prec n) \- ->
define (\n m f -> n (m f)) \* ->
define (\n m -> m (* n) 1) \exponential ->
define (* 10 10) \100 ->
define (* 10 100) \1000 ->
define (* 10 1000) \10000 ->
define (* 10 10000) \100000 ->
define (* 10 100000) \1000000 ->
define (\n -> n (const true) false) \isPositive ->
define (\n -> n (const false) true) \isZero ->
define (\n m -> isPositive (- n m)) \> ->
define (\n m -> isPositive (- m n)) \< ->
define (\n m -> isZero (- m n)) \>= ->
define (\n m -> isZero (- n m)) \<= ->
define (\n m -> and (<= n m) (>= n m)) \= ->
define (\n m -> or (< n m) (> n m)) \/= ->
define (fix (\fac n -> isZero n 1 (* n (fac (prec n)))))
\factorial ->
define (fix (\len xs -> isNil xs 0 (succ (len (cdr xs)))))
\length ->
define (fix (\sum xs -> isNil xs 0 (+ (car xs) (sum (cdr xs)))))
\sum ->
define (\size -> fix (\gen n -> > n size nil (cons n (gen (succ n)))) 1)
\genList ->
sum (* 1000 1000 (cons 0) nil) f x