I had same thoughts on being defined inside the class ... it's quite common out there but here I see it's very easy to create conflicts between classes.
What if a generic point2d + point3d is defined in both point2d class and point3d one ? IIRC Python just consider it's own representation during one operation, not associating it with "the caller" of such operation ... actually, I've always been envious of these: http://rgruet.free.fr/PQR26/PQR2.6.html#SpecialMethods Best Regards On Sun, Jan 12, 2014 at 3:45 AM, Axel Rauschmayer <[email protected]> wrote: > That is out of date compared to > > http://www.slideshare.net/BrendanEich/js-resp > > > Thanks! > > specifically slide 15: > > > http://image.slidesharecdn.com/jsresp-130914140214-phpapp02/95/slide-15-638.jpg?1379296961 > > which has: > > value class point2d { // implies typeof “point2d” > constructor point2d(x, y) { > this.x = +x; > this.y = +y; > // implicit Object.freeze(this) on return > } > point2d + number (a, b) { > return point2d(a.x + b, a.y + b); > } > number + point2d (a, b) { > return point2d(a + b.x, a + b.y); > } > point2d + point2d (a, b) { > return point2d(a.x + b.x, a.y + b.y); > } > // more operators, suffix declaration handler, etc. > } > > The idea is to provide convenient declartive syntax for operator > multimethods that dispatch along the lines proposed by Christian Hansen. > Some work required to handle subclassing, Christian has been helping, > writing it up is on my plate for this month. > > > Nice! Should the operator (case) definitions really be inside the class? > E.g., conceptually, number + point2d does not belong to a single class, it > belongs to both. Hence, I’d use something more like a (global) function > declaration: > > ``` > function number + point2d (a, b) { > > return point2d(a + b.x, a + b.y); > } > ``` > > Or, possibly: > > ``` > function + (a :: number, b :: point2d) { > > return point2d(a + b.x, a + b.y); > } > ``` > > Axel > > -- > Dr. Axel Rauschmayer > [email protected] > > home: rauschma.de > twitter: twitter.com/rauschma > blog: 2ality.com > > > > > _______________________________________________ > 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

