Unary negation operator
betseg opened this issue Β· comments
βοΈ Proposed change
Adding a new operator for negating an expression. I'm thinking of π, because positive values are above the negative ones, and this emoji is vertical.
π€ Rationale
It's useful π€·
πΊExample
π¦ a 3
π¦ b πa
βͺοΈ π b -3
or
π¦ a 3
π¦ b πa
βͺοΈ π b π3
I think β is more intuitive. In 0.6 binary operators are infix anyway, so this should work just fine:
3 β‘οΈ a
βa β‘οΈ b
βͺοΈ b π -3 π π...
yeh forgot that, nice.
also, β3 π -3
?
β3 π -3
Yep.
β
is actually not possible β I realised when I first tried to implement this β because it is ambiguous. For instance:
π€ 10 β4βοΈ
Is this a method call on 10
with one argument or on 6
with no arguments?
We need to reconsider alternatives. The original π
might not be optimal as it is very similar to π, which is a flow control statement but not an operator.
Why do you need a new operator in the first place? Why don't the minus sign work?
In every other languages I know of, you use the minus sign for this.
In Java, these two lines gives the same result:
a = 0 - b;
a = -b;
As I stated before, itβs ambiguous. Technically it is possible, of course, but it probably isn't what you'd expect.
The lines you showed work in Emojicode just as well, but Java has a completely different call syntax than Java, that does not allow the ambiguity seen above:
10.beQuiet(-4)
// or
(10 -4).beQuiet(4)
π because batteries have a positive and a negative side? Or 𧲠because magnets have a north and a south poles?