Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created June 9, 2017 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/271936cc2c98911666cbb2bc106d914b to your computer and use it in GitHub Desktop.
Save JoshCheek/271936cc2c98911666cbb2bc106d914b to your computer and use it in GitHub Desktop.
Lambda calculusified version of `[1, 2, 1, 3].forEach(n => console.log(n))`
(TO_I => (n0 => (n1 => (n2 => (n3 =>
(IF => (FALSE => (TRUE => (TO_BOOL =>
(IS_EMPTY => (CDR => (CAR => (CONS => (EMPTY_LIST =>
(y => (reduce => (PRINT =>
// This program is the lambda calculus translation of:
// [1, 2, 1, 3].forEach(n => console.log(n))
(list =>
reduce((n => _ => PRINT(TO_I(n))))
(list)
(n1))
(CONS(n1)
(CONS(n2)
(CONS(n1)
(CONS(n3)
(EMPTY_LIST)))))
)(x => console.log(x) || x) // interop: PRINT
)(y(recur =>
f => list => a =>
IF(IS_EMPTY(list))
(_ => a)
(_ => recur(f)
(CDR(list))
( f(CAR(list))(a) ))))
)(f =>
(buildRecur => a =>
f(buildRecur(buildRecur))(a))
(buildRecur => a =>
f(buildRecur(buildRecur))(a)))
)(f => f(TRUE)(TRUE)(TRUE))
)(data => link =>
f => f(data)(link)(FALSE))
)(list => list(data => link => is_empty => data))
)(list => list(data => link => is_empty => link))
)(list => list(data => link => is_empty => is_empty))
)(b => b(true)(false)) // interop: TO_BOOL
)(t => f => t)
)(t => f => f)
)(b => t => f => b(t)(f)(_=>_))
)(f => a => n2(f)(f(a)))
)(f => a => n1(f)(f(a)))
)(f => a => n0(f)(f(a)))
)(f => a => a)
)(int => int(n => n + 1)(0)) // interop: TO_INT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment