Just a bit related and perhaps of interest: Back when I believed in operator overloading, I wrote a package to allow C++ classes to inherit consistent overloading. The package consisted of templatized base classes that defined say the binary + operator in terms of +=. The base class parameter was the derived class, so the signatures of the operators would be correct, even though they were defined in a base class: http://en.wikipedia.org/wiki/Barton%E2%80%93Nackman_trick.
The bit about pumping types up into a base class is what interested most folks, but abstracting systematic overloading was the goal. Operator overloading is pretty hard on readers. A meta-type that succinctly describes the nature of the operators helps. It might be a lot easier in JS. jjb On Mon, Mar 26, 2012 at 8:48 PM, Tab Atkins Jr. <[email protected]>wrote: > On Mon, Mar 26, 2012 at 6:23 PM, Allen Wirfs-Brock > <[email protected]> wrote: > > As a followup, I've written a strawman[1] that explains how we could > specify > > and implement operator overloading that supports an open-ended set of > value > > types. I look at this as an adjunct to Dave's proposal that suggests > that > > the coercion/promotion rules should be pushed out of the actual operator > > semantics and placed into an extensible set of methods. > > > > [1] > http://wiki.ecmascript.org/doku.php?id=strawman:operator_overloading_with_double_dispatch > > Python (and others, like my own slow homebrew version of operator > overloading in JS) provide all binary operations as 'foo' and 'rfoo'. > If the lvalue overloads 'foo', that's used. Otherwise, if the rvalue > overloads 'rfoo', that's used. > > This makes it easier to define symmetric operations without having to > monkeypatch another class. It's limited, of course, since you have to > ensure that the lval doesn't preempt you with its own overload that > doesn't understand how to use you. In the future when we have guards > (and, presumably, guard-based overloads), this limitation can be > avoided as well. > > ~TJ > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

