Python Forum

Full Version: Expanding on (+,*,%,/,//, etc...)= operator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I had an idea for how we write shorthand for a few binary functions (I'll use + as my example).

When we write
x += 2
, it really means
x = x + 2
, more generally since we can write addition as a binary relation, we can define it as
f
and then equivalently
x = f(x,2)
in that case, why not write the original statement as
x f= 2
?

On top of that for any function which isn't even binary, applying the same idea would yield the following shorthand for
x = g(x, a, b, c, ...)
to be
x g= a,b,c,...
What do you think?
I think lines such as x = g(x, a, b, c) are not frequent enough to deserve such a special syntactic treatment. A language's syntax is a coherent set of carefully planned rules. Every odd idea must not be implemented.