I have been thinking about order operations and generalized * in Python recently. I want to share some of my thinking here, even the topic is quite theoretical, considering the beauty and orthogonality of the language.
You can do comparison with tuples of numbers in Python
>>> (0,0)<(1,1)<(2,2) True >>> (0,0)<(1,1)<(2,0) True >>>
First is fine for me, but I am not agreeing with the second one. Why?
If a<b<c, then number b is between a and c in the number line.
(x,y) is point in two dimensional plane. For me the natural extension of < is for it to mean that
(a,b) < (c,d) < (e,f)
means that (c,d) is inside a square whose corners are (a,b) and (e,f). That is same as
a<c<e and b<d<f
There is + generalized for many types, but I think it would be nice and logical that there would be opposite -:
>>> (0,1) * 2 (0, 1, 0, 1) >>> _ / 2 Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> _ / 2 TypeError: unsupported operand type(s) for /: 'tuple' and 'int' >>> 'abcd'+'ef' 'abcdef' >>> _ - 'ef' Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> _ - 'ef' TypeError: unsupported operand type(s) for -: 'str' and 'str' >>>
By logic /2 should mean half of sequence and - should mean removing the sequence from the end of first sequence.
What you think? Could there be easy way to program these things to function?