4 ms·
Gavin Howard here. There really isn't a design choice to be made. POSIX requires unary negation to have higher precedence. The only precedence change (I can r
by gavinhoward 2y ago
Gavin Howard here.
There really isn't a design choice to be made. POSIX requires unary negation to have higher precedence.
The only precedence change (I can remember) from GNU bc is that I changed the not operator to have the same precedence as negation. This was so all unary operators had the same precedence, which leads to more predictable parsing and behavior.
- shagie 2y agoThe question that I'm curious about is "why does POSIX require unary negation to have a higher precedence?" Was it a "this is the way that bc worked in the 70s because it was easier to write a parser for it?" or was there some more underlying reason for the "this problem gets really icky if unary negation has lower precedence than the binary operators and makes for other expressions that become less reasonable?" It's like the Logical XOR issue ( https://youtu.be/4PaWFYm0kEw?t=2236&si=Wi0gwV-XctLGN98I https://youtu.be/4PaWFYm0kEw?t=2236&si=Wi0gwV-XctLGN98I ) ... and I'm of the opinion that there's a real reason why this design choice was made. (Aside: Some other historical "why things work that way" touching on dc's place in history: Ken Thompson interviewed by Brian Kernighan at VCF East 2019 https://youtu.be/EY6q5dv_B-o?si=YKr4j_FAEp-OihiX&t=1784 https://youtu.be/EY6q5dv_B-o?si=YKr4j_FAEp-OihiX&t=1784 - it goes on to pipes and dc makes an appearance there again)
- gavinhoward 2y agoUnfortunately, I can't really say much about historical design.