4 ms·
Perhaps having unary minus (and especially unary plus) is just a bad idea in general; just mandate "0 - expr". To make negative constants work properly, you sti
by Joker_vD 7mo ago
Perhaps having unary minus (and especially unary plus) is just a bad idea in general; just mandate "0 - expr". To make negative constants work properly, you still have to either special case literals "256", "65536", etc. and ideally check whether they got negated or not, or introduce a special syntax just for them, like "~1" of ML for negative one, or "-1" (which you are not allowed to break with whitespace) of some other language I've forgotten the name of.
While we're at it, probably the unary bitwise complement could go as well? Obviously, "^(0-1)" would suck to write but since 99% of the time bitwise "not" used in expressions/statements like "expr &~ mask..." or "var &= ~mask", I feel like simply having binary "and-not" operator that looks like "&~" or "&^" (Golang) is just better.
Also, a small prize (a "thank you!" from a stranger on the Internet i.e. me) to someone who can propose a good syntax for compound assignment with reversed subtraction:
x ^= 0-1 # in-place bitwise complement
x ^= true # in-place logical negation
x ?= 0 # in-place integer negation???
- teo_zero 7mo ago+1 on the convenience of a "mask" operator that perform the and-not. It's an operation that's used more often than others which do have the privilege of having their own symbol, like xor.
- xigoi 7mo ago> Also, a small prize (a "thank you!" from a stranger on the Internet i.e. me) to someone who can propose a good syntax for compound assignment with reversed subtraction: I would do away with operator-assign operators and instead introduce a general syntax for updating a variable that can be used with any expression. x = _ + 1 # increment x x = 0 - _ # negate x output = sanitizeHtml(_) index = (_ + 1) % len(arr)
- Joker_vD 7mo agoThank you! Having a syntactical construct to reference the value of the lhs of the assignment's operator in its rhs without recalculating it is a pretty nifty trick: it works because there is only one lvalue on the lhs of an assignment, so there is no ambiguity to what it refers to. And it could even be extended to work with multivalued assignments, although less neatly. Amazing! Thank you again!