|
| 1 | +(import std.Testing) |
| 2 | + |
| 3 | +(let _true (fun (x) |
| 4 | + (fun (y &x) x))) |
| 5 | +(let _false (fun (x) |
| 6 | + (fun (y) y))) |
| 7 | +(let _not (fun (b) |
| 8 | + ((b _false) _true))) |
| 9 | +(let _and (fun (b1) |
| 10 | + (fun (b2 &b1) |
| 11 | + ((b1 b2) _false)))) |
| 12 | +(let _or (fun (b1) |
| 13 | + (fun (b2 &b1) |
| 14 | + ((b1 _true) b2)))) |
| 15 | + |
| 16 | +(let _zero (fun (f) (fun (x) x))) |
| 17 | +(let _succ (fun (n) |
| 18 | + (fun (f &n) |
| 19 | + (fun (x &n &f) |
| 20 | + (f ((n f) x)))))) |
| 21 | +(let _pred (fun (n) |
| 22 | + (fun (f &n) |
| 23 | + (fun (x &n &f) |
| 24 | + (((n (fun (g &f) (fun (h &g &f) (h (g f))))) (fun (u &x) x)) (fun (a) a)))))) |
| 25 | +(let _one (_succ _zero)) |
| 26 | + |
| 27 | +(let read_church (fun (n) |
| 28 | + ((n (fun (x) (+ x 1))) 0))) |
| 29 | +(let read_bool (fun (b) |
| 30 | + ((b true) false))) |
| 31 | + |
| 32 | +(test:suite lambda { |
| 33 | + (test:case "logic" { |
| 34 | + (test:eq (read_bool _true) true) |
| 35 | + (test:eq (read_bool _false) false) |
| 36 | + |
| 37 | + (test:case "not" { |
| 38 | + (test:eq (read_bool (_not _true)) false) |
| 39 | + (test:eq (read_bool (_not _false)) true) }) |
| 40 | + |
| 41 | + (test:case "and" { |
| 42 | + (test:eq (read_bool ((_and _true) _true)) true) |
| 43 | + (test:eq (read_bool ((_and _true) _false)) false) |
| 44 | + (test:eq (read_bool ((_and _false) _true)) false) |
| 45 | + (test:eq (read_bool ((_and _false) _false)) false) }) |
| 46 | + |
| 47 | + (test:case "or" { |
| 48 | + (test:eq (read_bool ((_or _true) _true)) true) |
| 49 | + (test:eq (read_bool ((_or _true) _false)) true) |
| 50 | + (test:eq (read_bool ((_or _false) _true)) true) |
| 51 | + (test:eq (read_bool ((_or _false) _false)) false) })}) |
| 52 | + |
| 53 | + (test:case "church numerals" { |
| 54 | + (test:case "zero / succ" { |
| 55 | + (test:eq (read_church _zero) 0) |
| 56 | + (test:eq (read_church _one) 1) |
| 57 | + (test:eq (read_church (_succ _one)) 2) |
| 58 | + (test:eq (read_church (_succ (_succ _one))) 3) }) |
| 59 | + |
| 60 | + (test:case "pred" { |
| 61 | + (test:eq (read_church (_pred _one)) 0) |
| 62 | + (test:eq (read_church (_pred (_succ _one))) 1) |
| 63 | + (test:eq (read_church (_pred (_succ (_succ _one)))) 2) })})}) |
0 commit comments