Created
August 22, 2018 14:35
-
-
Save jimmyhmiller/fc0393be82b81dee9b436d0bdbc8e841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Thread first of https://tinyurl.com/yc2vzjm3 | |
(-> 0 | |
1 | |
(num | |
1) | |
fizzbuzz | |
(λfizzbuzz. | |
λn. | |
((for | |
n) | |
λi. | |
((do2 | |
(((if | |
(zero? | |
((% | |
i) | |
3))) | |
λ_. | |
(((if | |
(zero? | |
((% | |
i) | |
5))) | |
λ_. | |
(print-list | |
fizzbuzzmsg)) | |
λ_. | |
(print-list | |
fizzmsg))) | |
λ_. | |
(((if | |
(zero? | |
((% | |
i) | |
5))) | |
λ_. | |
(print-list | |
buzzmsg)) | |
λ_. | |
(print-list | |
(itoa | |
i))))) | |
(print-newline | |
nil)))) | |
(λfizzbuzzmsg. | |
((cons | |
(((num | |
0) | |
7) | |
0)) | |
((cons | |
(((num | |
1) | |
0) | |
5)) | |
((cons | |
(((num | |
1) | |
2) | |
2)) | |
((cons | |
(((num | |
1) | |
2) | |
2)) | |
((cons | |
(((num | |
0) | |
9) | |
8)) | |
((cons | |
(((num | |
1) | |
1) | |
7)) | |
((cons | |
(((num | |
1) | |
2) | |
2)) | |
((cons | |
(((num | |
1) | |
2) | |
2)) | |
nil))))))))) | |
(λbuzzmsg. | |
((cons | |
(((num | |
0) | |
6) | |
6)) | |
((cons | |
(((num | |
1) | |
1) | |
7)) | |
((cons | |
(((num | |
1) | |
2) | |
2)) | |
((cons | |
(((num | |
1) | |
2) | |
2)) | |
nil))))) | |
(λfizzmsg. | |
((cons | |
(((num | |
0) | |
7) | |
0)) | |
((cons | |
(((num | |
1) | |
0) | |
5)) | |
((cons | |
(((num | |
1) | |
2) | |
2)) | |
((cons | |
(((num | |
1) | |
2) | |
2)) | |
nil))))) | |
(λitoa. | |
λn. | |
(((Y | |
λrecurse.λn.λresult. | |
(((if | |
(zero? | |
n)) | |
λ_. | |
(((if | |
(nil? | |
result)) | |
λ_. | |
((cons | |
zero-byte) | |
nil)) | |
λ_.result)) | |
λ_. | |
((recurse | |
((/ | |
n) | |
10)) | |
((cons | |
((+ | |
zero-byte) | |
((% | |
n) | |
10))) | |
result)))) | |
n) | |
nil)) | |
(λzero-byte. | |
(((num | |
0) | |
4) | |
8)) | |
(λprint-newline. | |
λ_. | |
(print-byte | |
(((num | |
0) | |
1) | |
0))) | |
(λprint-list. | |
(Y | |
λrecurse.λl. | |
(((if | |
(nil? | |
l)) | |
λ_.void) | |
λ_. | |
((do2 | |
(print-byte | |
(car | |
l))) | |
(recurse | |
(cdr | |
l)))))) | |
(λprint-byte. | |
PRINT_BYTE) | |
(λfor. | |
λn.λf. | |
((((Y | |
λrecurse.λremaining.λcurrent.λf. | |
(((if | |
(zero? | |
remaining)) | |
λ_.void) | |
λ_. | |
((do2 | |
(f | |
current)) | |
(((recurse | |
(pred | |
remaining)) | |
(succ | |
current)) | |
f)))) | |
n) | |
0) | |
f)) | |
(λdo4. | |
λa.do3) | |
(λdo3. | |
λa.do2) | |
(λdo2. | |
λa.λb.b) | |
(λcdr. | |
λl. | |
(pair-second | |
(pair-second | |
l))) | |
(λcar. | |
λl. | |
(pair-first | |
(pair-second | |
l))) | |
(λcons. | |
λe.λl. | |
((make-pair | |
true) | |
((make-pair | |
e) | |
l))) | |
(λnil?. | |
λl. | |
(not | |
(pair-first | |
l))) | |
(λnil. | |
((make-pair | |
false) | |
void)) | |
(λ%. | |
λm.λn. | |
((- | |
m) | |
((* | |
((/ | |
m) | |
n)) | |
n))) | |
(λ/. | |
(Y | |
λ/.λm.λn. | |
(((if | |
((eq? | |
m) | |
n)) | |
λ_.1) | |
λ_. | |
(((if | |
(zero? | |
((- | |
m) | |
n))) | |
λ_.0) | |
λ_. | |
((+ | |
1) | |
((/ | |
((- | |
m) | |
n)) | |
n)))))) | |
(λeq?. | |
λm.λn. | |
((and | |
(zero? | |
((- | |
m) | |
n))) | |
(zero? | |
((- | |
n) | |
m)))) | |
(λ-. | |
λm.λn. | |
((n pred) | |
m)) | |
(λpred. | |
λn. | |
(((λn.λf.λx. | |
(pair-second | |
((n | |
λp. | |
((make-pair | |
(f | |
(pair-first | |
p))) | |
(pair-first | |
p))) | |
((make-pair | |
x) | |
x))) | |
n) | |
succ) | |
0)) | |
(λzero?. | |
λn. | |
((n λ_.false) | |
true)) | |
(λpair-second. | |
λp. | |
(p false)) | |
(λpair-first. | |
λp. | |
(p true)) | |
(λmake-pair. | |
λx.λy.λt. | |
((t x) y)) | |
(λor. | |
λa.λb. | |
((a true) b)) | |
(λand. | |
λa.λb. | |
((a b) false)) | |
(λnot. | |
λp.λt.λf. | |
((p f) t)) | |
(λif. | |
λp.λa.λb. | |
(((p a) b) void)) | |
(λfalse. | |
λt.λf.f) | |
(λtrue. | |
λt.λf.t) | |
(λnum. | |
λa.λb.λc. | |
((+ | |
((+ ((* ((* 10) 10)) a)) | |
((* 10) b))) | |
c)) | |
(λ10. | |
(succ 9)) | |
(λ9. | |
(succ 8)) | |
(λ8. | |
(succ 7)) | |
(λ7. | |
(succ 6)) | |
(λ6. | |
(succ 5)) | |
(λ5. | |
(succ 4)) | |
(λ4. | |
(succ 3)) | |
(λ3. | |
(succ 2)) | |
(λ2. | |
(succ 1)) | |
(λ1. | |
(succ 0)) | |
(λ*. | |
λm.λn.λx. | |
(m (n x))) | |
(λ+. | |
λm.λn.λf.λx. | |
((((m succ) n) f) x)) | |
(λsucc. | |
λn.λf.λx. | |
(f ((n f) x))) | |
(λ0. | |
λf.λx.x) | |
(λvoid. | |
λx. | |
(U U)) | |
(λY. | |
(U λh.λf. (f λx. (((h h) f) x)))) | |
(λU. | |
λf. | |
(f f))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment