Python dot-equals (syntax proposal)
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun May 2 05:24:23 EDT 2010
On Sun, 02 May 2010 17:09:36 +1000, Lie Ryan wrote:
> On 05/02/10 10:58, Steven D'Aprano wrote:
>> On Sun, 02 May 2010 05:08:53 +1000, Lie Ryan wrote:
>>
>>> > On 05/01/10 11:16, Steven D'Aprano wrote:
>>>> >> On Fri, 30 Apr 2010 12:34:34 -0400, D'Arcy J.M. Cain wrote:
>>>> >>
>>>> >> In practice though, I think that's a difference that makes no
>>>> >> difference. It walks like an operator, it swims like an operator,
>>>> >> and it quacks like an operator.
>>>> >>
>>>> >>
>>> > Nope it's not. A full-time operator in python have a reflected
>>> > version (e.g. __radd__), which dot does not have.
>> What are the reflected versions of __eq__ and __ne__ (binary == and !=
>> operators)?
>
> Python do not have them now, but it does make sense if python have
> them[1]. OTOH, given current python's language semantic, __rgetattr__
> doesn't make any sense; adding __rgetattr__ would require a quite
> fundamental change to the language's semantic, primarily how attribute
> resolution works.
>
> [1] though they'd probably be dismissed as bad idea since equality and
> inequality are supposed to be a symmetric relation; reflected
> (in)equality makes it way too easy to break that premise
>
>> And __neg__, __pos__ and __inv__ (for the unary - + and ~ operators)?
>>
>> And the three-argument form of __pow__ for power(1, 2, x)?
>
> I know you're a famed nitpicker, but don't be silly, reflected operator,
> by definition, only makes sense for binary operator.
Binary operators aren't the only kind of operator, and you claimed that:
"A full-time operator in python have a reflected version".
But there are full-time operators that don't have reflected versions, so
your claim is just *wrong*. It would still be wrong even if you had
limited yourself to binary operators.
I have agreed with you that there are useful things people might want to
do (e.g. function composition) that you can't do because the "dot
operator" isn't a *real* operator with exactly the same semantics as
"plus operator", "multiply operator" and friends. I think we're in
violent agreement, and merely disagreeing over semantics. There's no need
to continue arguing against a position I haven't actually taken :)
--
Steven
More information about the Python-list
mailing list