Last active
November 17, 2015 10:48
-
-
Save agentcooper/e5bc0591367b1328231c to your computer and use it in GitHub Desktop.
sicp.js
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
// node --harmony index.js | |
var cons = (a, b) => (f) => f(a, b); | |
var car = (p) => p((p, q) => p); | |
var cdr = (p) => p((p, q) => q); | |
var list = (first, ...rest) => | |
!first ? | |
null : | |
cons(first, list(...rest)); | |
var append = (items0, items1) => | |
items0 === null ? | |
items1 : | |
cons(car(items0), append(cdr(items0), items1)) | |
var reverse = (items) => | |
items === null ? | |
items : | |
append(reverse(cdr(items)), list(car(items))); | |
var printList = (items) => | |
items !== null ? | |
(console.log(car(items)), printList(cdr(items))) : | |
null; | |
var l0 = list('a', 'b', 'c', 'd', 'e'); | |
printList(reverse(l0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment