Re: [VOTE] Userspace operator overloading

From: Date: Sat, 28 Mar 2020 16:27:43 +0000
Subject: Re: [VOTE] Userspace operator overloading
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-109395@lists.php.net to get a copy of this message
On Sat, 2020-03-28 at 17:05 +0100, Christoph M. Becker wrote: > On 28.03.2020 at 15:57, Johannes Schlüter wrote: > > > On March 28, 2020 1:25:11 PM GMT+01:00, "Christoph M. Becker" < > > cmbecker69@gmx.de> wrote: > > > > > This "try left/right" approach is how operator overloading works > > > for > > > internal classes[1], and apparently, it works quite well, as long > > > as it > > > is not overused. > > > > The fact that it works in one or two cases as an implementation > > detail where the full implementation is controlled by a single > > group (internals) is no indication for it to work at large. > > Fair enough. But maybe Python, where userland operator overloading > works similar to the proposal at hand, is? :) It doesn't: Python 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... def __add__(self, other): ... print("add") ... >>> a = A() >>> a + 1 add >>> 1 + a Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'A' johannes

« previous php.internals (#109395) next »