Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created May 1, 2013 22:09
Show Gist options
  • Save swannodette/5498773 to your computer and use it in GitHub Desktop.
Save swannodette/5498773 to your computer and use it in GitHub Desktop.
console.log("hello");
function LazySeq(head, tail) {
this.head = head; // value
this.tail = tail; // thunk || null
}
function ints(n) {
return new LazySeq(n, function() { return ints(n+1); });
}
var integers = ints(0);
function take(n, seq) {
if(n==0) return null;
return new LazySeq(seq.head, function() { return take(n-1, seq.tail() )});
}
function into_array(seq) {
var res = [];
while(seq) {
res.push(seq.head);
seq = seq.tail();
}
return res;
}
function nontail(x) {
if(x==0) return x;
return 1+nontail(x-1);
}
function niter(x, acc) {
if(x==0) return acc;
return niter(x-1, acc+1);
}
function ntramp(x, acc) {
if(x==0) return acc;
return function() { return ntramp(x-1, acc+1) };
}
function trampoline(f) {
while(typeof f == 'function') {
f = f();
}
return f;
}
function prop(x) {
return function(o) {
return o[x];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment