I recently watched most of the Structure and Interpretation of Computer Programs (SICP) lectures and along the way I learned about the completely data-less representation available for Lisp's cons car and cdr functions. It was pretty mind blowing and just so I could feel smart for a couple minutes I ported it to Javascript, a language with almost all of Lisp's cool features but with C's syntax.
function cons(x, y) {
return function(m) {
m(x, y);
};
}
function car(x) {
x(function(a,d) {
return a;
});
}
function cdr(x) {
x(function(a,d) {
return d;
});
}
Comments
Post new comment