Created
August 30, 2017 01:39
-
-
Save jooyunghan/1806f0607d48f0bdf1e007667062d8dd to your computer and use it in GitHub Desktop.
Pair implementation in Smalltalk-72 style
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 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.106.9352&rep=rep1&type=pdf