Last active
June 16, 2016 15:24
-
-
Save keyvanakbary/601882c851e4ed56b064913e8480fed0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const cons = (x, y) => (m) => m(x, y); | |
const car = (z) => z((p, q) => p); | |
const cdr = (z) => z((p, q) => q); | |
const pair = cons(1, 2); | |
console.log(car(pair), cdr(pair));//1 2 | |
const list = cons(1, cons(2, cons(3, cons(4, null)))); | |
const each = (l, fn) => cdr(l) ? (() => {fn(car(l)); each(cdr(l), fn)})() : fn(car(l)); | |
each(list, console.log);//1 2 3 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment