Operator overloading revisited
P T Withington
ptw at pobox.com
Wed Jul 1 09:58:52 PDT 2009
On 2009-07-01, at 03:48EDT, Christian Plesner Hansen wrote:
> Methods live on objects and their prototypes.
Only if you co-opt the word "method" to mean that. I would claim this
is just shorthand for "instance method". There is also "class method"
or "static method". There are other definitions (see below).
On 2009-07-01, at 10:23EDT, Brendan Eich wrote:
> How much sweeter could this be sugared?
>
> function "+"(a :Point, b :Number) {
> return new Point(a.x + b, a.y + b);
> }
>
> function "+"(a :Number, b :Point) {
> return new Point(a + b.x, a + b.y);
> }
>
> function "+"(a :Point, b :Point) {
> return new Point(a.x + b.x, a.y + b.y);
> }
>
> (Here the quoted operator names imply multimethod addition, where
> previously I used |generic function| to Tucker's enthusiastic +∞).
Indeed.
Not to suggest paint, but I think the syntactic sugar of Dylan has a
nice color:
`a + b` is sugar for `\+(a, b)`
`\+` is a generic function (of 2 arguments) to which you can add
"methods". Methods are just syntactic sugar for specifying the
branches of a dispatch algorithm (http://portal.acm.org/citation.cfm?id=236338.236343
). [That is since `+` is not a legal identifier, you have to escape
it to use it as an identifier, to name a generic function.]
If "method" has to be used uniquely in Javascript as the word that
means a computation attached to an instance, maybe we just need a new
word to mean "dispatch element of a generic function". I would have
said "generic function method", which (ambiguously) gets abbreviated
to "method", and may be the source of objection?
More information about the es-discuss
mailing list