Skip to content

Instantly share code, notes, and snippets.

@2-3
Last active December 14, 2018 20:51
Show Gist options
  • Save 2-3/148b14162e848d9a9777c789ed17ed1e to your computer and use it in GitHub Desktop.
Save 2-3/148b14162e848d9a9777c789ed17ed1e to your computer and use it in GitHub Desktop.
function make_object(_super, _recvs_) {
var _recvs = Object.assign(
{ lookup: function(s, al) { return _lookup(al[0]); },
super: function(s, al) { return _call(_super('lookup', [al[0]]), al.slice(1)); }}, _recvs_);
var _lookup = function(n) {
if (n in _recvs) { return _recvs[n]; }
else if (_super != undefined) { return _super('lookup', [n]);}
else { throw 'InvalidMessage'; }}
var _self = function(n, al) { return _call(_lookup(n), al);}
var _call = function(r, al) { return r(_self, al);}
return function(msg, args) { return _call(_lookup(msg), args); }};
function _point(x, y) {
return make_object(
undefined,
{ posn: function(s, al) { return [x, y]; },
eql: function(s, al) {
var sp = s('posn', []);
var rp = al[0]('posn', []);
return ( sp[0] == rp[0] && sp[1] == rp[1]);},
sum: function(s, al) { return x + y;}})}
function _point3d(x, y, z) {
return make_object(
_point(x, y),
{ posn: function(s, al) { return [x, y, z]; },
sum: function(s, al) { return z + s('super', ['sum']);}})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment