4 ms·
Negative literals/negation/subtraction sharing "-" leads to odd corner cases in the grammars of quite a few languages. I'm rather fond of the J approach: -1 is
by RodgerTheGreat 11y ago
Negative literals/negation/subtraction sharing "-" leads to odd corner cases in the grammars of quite a few languages. I'm rather fond of the J approach: -1 is the application of the negation operator to the literal one. _1 is the literal negative one. This is a very important distinction in J since you can have whitespace-delimited lists of numbers. "-1 2 3" is equivalent to "_1 _2 _3".
- oinksoft 11y agoThis is also true of Standard ML, where unary minus is ~, and APL, where unary minus is ¯
- pklausler 11y agoTo be most clear: The "high minus" in APL is not the unary negation function; it's part of the syntax for a negative numeric literal. If X is 1, "-X" computes "¯1", and "¯X" is ill-formed.