-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.lc
46 lines (34 loc) · 1.01 KB
/
example.lc
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
# This is using the standard library function POW, ints are Church Numerals, bools are Church Booleans
int :: POW 2 3;
# This is the same result but printed as a function
function :: POW 2 3;
# Same as above
POW 2 3;
# If you try to print as a datatype when it is not, it will revert to a function
bool :: POW 2 3;
# This is an example of an actual bool
bool :: IS_EVEN 6;
IS_EVEN 6;
# 0 happens to be defined as equal to FALSE
0;
FALSE;
int :: IS_EVEN 7;
# However TRUE is not a valid int
1;
TRUE;
int :: IS_EVEN 6;
# You can define your own functions as well
MY_FUNC := (\b.\e.e b);
# MY_FUNC happens to be the same as the stdlib function POW
int :: MY_FUNC 2 3;
# You can use a combination of backslash and λ
(\hi_im_a_var.λim_also_a_var.TRUE 1 0);
# We can get fancy with recursion using the Y-Combinator stdlib function
MY_REC := Y (\r.\m.
IF_THEN_ELSE (IS_ZERO m)
1
( MULT m (r (PRED m)) )
);
# This prints factorial(4)
int :: MY_REC 4;
# You can take it from there (whitespace is ignored!)