Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Created August 30, 2017 01:39
Show Gist options
  • Save jooyunghan/1806f0607d48f0bdf1e007667062d8dd to your computer and use it in GitHub Desktop.
Save jooyunghan/1806f0607d48f0bdf1e007667062d8dd to your computer and use it in GitHub Desktop.
Pair implementation in Smalltalk-72 style
function pair(left, right) {
return {
left() {
if (arguments.length == 1) left = arguments[0];
return left;
},
right() {
if (arguments.length == 1) right = arguments[0];
return right;
},
toString() {
return `(${left}, ${right})` ;
},
print() {
console.log(String(this));
}
};
}
let c = pair("john", "lenon");
c.print();
let d = pair("abc", "def");
c.left(d);
c.print();
@jooyunghan
Copy link
Author

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.106.9352&rep=rep1&type=pdf

☞ pair ← class | left right
  (
  ¤ isnew  ⇒ ( ☞ left ← ☐.  ☞ right ← ☐. )
  ¤ left ⇒ ( ¤ ← ⇒ (⇑ ☞ left ← ☐)  ⇑ left. )
  ¤ right ⇒ ( ¤ ← ⇒ (⇑ ☞ right ← ☐)  ⇑ right. )
  ¤ print ⇒ ( '(' print. left print. ',' print. right print. ')' print. )
  )!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment