Why does 2- - - -1=3?
mathematically, it's correct. by why would a programming language allow that? maybe i just lack imagination, but i can't think of any reason why you would want to explicitly string together plus or minus signs. and if you did do that, it is likely a typo as in the original post. if it's done through variables, then it should definitely be allowed (ie, a = -1;  2 -a should be 3). some languages allow for i++ to increment i. and python allows i += 1 to increment i. not throwing a syntax error just seems confusing to me, even if it is mathematically correct.
I recently ran into a bug using python (v3.6.8) and pandas (v0.23.4) where I was trying to subtract a date offset. However, I accidentally typed two -- signs and it ended up adding the date offset instead. I did some more experimenting and found that 2--1 will return 3. This makes sense since you could interpret that as 2-(-1), but you can go even farther and string a bunch of negatives together 2----1 will return 3. I also replicated this in R and it does the same thing. Can anyone help me understand what's happening here?