-
-
Save superdav42/5320849 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
| function empty_list(selector) { | |
| return selector(undefined, undefined, true); | |
| }; | |
| function prepend(el, list) { | |
| return function(selector) { | |
| return selector(el, list, false); | |
| }; | |
| }; | |
| //selector | |
| function select(n) { | |
| return function from(list) { | |
| return list(function () { | |
| return arguments[n]; | |
| }); | |
| }; | |
| } | |
| var head = select(0); | |
| var tail = select(1); | |
| var is_empty = select(2); | |
| var names = prepend("Alice", | |
| prepend("Bob", | |
| prepend("Candice", | |
| empty_list))); | |
| console.log(is_empty(names)); | |
| // False | |
| console.log(head(names)); | |
| // Alice | |
| console.log(tail(names)); | |
| // Some function representing the list of ("Bob", "Candice") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment