Skip to content

Instantly share code, notes, and snippets.

@jbarnette
Last active January 13, 2017 00:04
Show Gist options
  • Save jbarnette/751075eb3271bc12b9a32273576a7628 to your computer and use it in GitHub Desktop.
Save jbarnette/751075eb3271bc12b9a32273576a7628 to your computer and use it in GitHub Desktop.
@discardableResult func cons(_ x: Any, _ y: Any) -> (((Any, Any) -> Any) -> Any) {
return { m in m(x, y) }
}
@discardableResult func car(_ z: (((Any, Any) -> Any) -> Any)) -> Any {
return z { p, q in p }
}
@discardableResult func cdr(_ z: (((Any, Any) -> Any) -> Any)) -> Any {
return z { p, q in q }
}
car(cons(1, 2))
cdr(cons(1, 2))
print(car(cons(1, cons(2, 3)))) // => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment