Skip to content

Instantly share code, notes, and snippets.

@bluurn
Created January 29, 2019 14:25
Show Gist options
  • Save bluurn/8c65b8debfc54fc49d3b2abd225a7f2b to your computer and use it in GitHub Desktop.
Save bluurn/8c65b8debfc54fc49d3b2abd225a7f2b to your computer and use it in GitHub Desktop.
JS: Pair Implementation
var cons = function (x, y) {
return function(message) {
switch (message) {
case 'car': {
return x;
}
case 'cdr': {
return y;
}
}
};
};
var car = function(pair) {
return pair('car');
};
var cdr = function(pair) {
return pair('cdr');
}
var pair = cons('a', 'b');
console.assert(car(pair) == 'a');
console.assert(cdr(pair) == 'b');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment