Unicode operators and precedence?
Dominikus Dittes Scherkl
dominikus at scherkl.de
Sun Nov 1 20:52:10 UTC 2020
On Sunday, 1 November 2020 at 20:15:00 UTC, Ola Fosheim Grøstad
wrote:
> On Sunday, 1 November 2020 at 19:47:33 UTC, Dominikus Dittes
> Scherkl wrote:
>>> opBinary!"·"
>> I would recommend to refrain from it as it is visual too
>> similar [to dot].
>
> It is center-dot, multiplication/inner product: vec1·vec2
> IDEs should colour it differently than the regular
> "vec1.length" operator
Ok, may work, but I still think it's no good idea.
>>> opBinary!"✕"
>>> opBinary!"⊗"
>>> opBinary!"⊘"
>>> opBinary!"⊙"
>> same as *, / ("point" arithmetic)
>
> I wonder if they should be one step higher so that they can be
> used for linear algebra? But I am not sure.
Yeah, one step higher prio would be good.
>>> opBinary!"∩"
>>> opBinary!"∪"
>> same as &, |, ^ ("set" arithmetic - bitwise is only a special
>> kind of set)
>
> IIRC D uses the same as C where "&", "|" have higher precedence
> than "==" which is not good.
>
> I want to be able to say "A∩B == C" and have it parse as "(A∩B)
> == C".
I don't understand. if & | ^ had higher prio than == everything
would be good.
SO yes, you are right, the prio of set operation should be higher
than comparison.
> > ! --> ¬ (logic not)
> > && --> ∨ (logic and)
> > || --> ∧ (logic or)
> I was thinking to use those for bitwise operators in order to
> overcome the precedence mess that currently exists.
No, they are clearly logic operators and should NOT have set
semantics.
Bitwise, as I mentioned, is only a special kind of set, so we
should use the set operators to overload bitwise arithmetic (I
always think of an unsigned value as a set of bits).
But I agree, logic should have higher prio than comparison, but
lower prio than set operators.
> > ^ --> ⊻ (xor - and add the missing ⊼ (nand) and ⊽ (nor))
> Also xor makes more sense bitwise.
Hmm. Maybe you are right - Xor, Nand and Nor are more useful as
additional set operators.
But And, Or and Not should be pure logic.
Ah, i missed one:
~ --> ∁ (complement)
And of course unary operators should have highest priority, no
matter if they are set, logic or whatever.
More information about the Digitalmars-d
mailing list