Re:Why Operators Are Useful
by vivekseth on Saturday March 16, 2019 @02:00PM
(#19409178)
If a+b != b+a that breaks the commutativity property of addition.
[ Parent
| on HN ]
Re:Why Operators Are Useful
by davidwtbuxton on Saturday March 16, 2019 @02:41PM
(#19409405)
Yes, but I still want this for combining dictionaries. Python already violates this property, I don't find it confusing.
Python 3.7.2 (default, Dec 30 2018, 08:55:50)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 'foo' + 'bar' == 'bar' + 'foo'
False
>>> ['foo'] + ['bar'] == ['bar'] + ['foo']
False"a"+"b" != "b"+"a" already.
That property is not universal, and it is currently being defined for Python dictionaries. You can't break a property that isn't defined yet. ;-)
Re:Why Operators Are Useful
by selimthegrim on Saturday March 16, 2019 @06:26PM
(#19410771)
Is this what changed in 3.5?
Commutatitivity does not need to always hold. Multiplication is not commutative on matrices, but we still use it often and write it as a product nonetheless
In mathematics, the ‘multiplication’ operation is not assumed to be commutative, whereas the ‘addition’ operator is used specifically to indicate commutativity. So, for example, using the plus sign for string concatenation goes against this tradition.
Re:Why Operators Are Useful
by whatshisface on Saturday March 16, 2019 @09:29PM
(#19411590)
Python actually supports a special operator @ for non-commutative matrix products.