[Python-ideas] Operator as first class citizens -- like in scala -- or yet another new operator?

Eric V. Smith eric at trueblade.com
Tue Jun 4 08:50:09 EDT 2019


On 6/4/2019 8:38 AM, Steven D'Aprano wrote:
> On Tue, Jun 04, 2019 at 01:20:14PM +0100, Rhodri James wrote:
>> On 04/06/2019 11:06, Yanghao Hua wrote:
>>> [...]  what I needed is an operator that does not
>>> collide with all existing number/matrix operators.
>>
>> Why?
>>
>> That's the question that in all your thousands of words of argument you
>> still haven't answered beyond "because I want it."
> 
> 
> 
> (1) Because they're already being used. That rules out operators that
> are supported by numbers at least, since the primitive values in his
> code are numbers.
> 
> So once you remove the operators supported by numbers:
> 
>      + - * / // & ** ^ & | << >> ~ < > <= >= == !=
> 
> (have I missed any?) I think that only leaves @ remaining.

One problem is that this has no end. Say <== is added (for "signals"), 
then someone will say "I want something just like a signal, but with 
this one additional operator". What then?

As sad as it may be to many people (and I'm one of them), Python just 
isn't the right fit for designing DSLs. And if we want to improve it in 
that area, SQL is the first place we should start looking. SQLAlchemy 
has any number of functions or weird use of operators (.in_(), &&, etc.) 
that could be improved. SQLAlchemy chose to just accept that Python is 
what it is, and did they best they could, even though some of the 
constructs are not ideal. And I think it's been pretty successful.

Eric


More information about the Python-ideas mailing list