Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I suppose different operators could still have different associativity in a language without precedence

That… is true, and I have a hard time computing how it would even work.



One way to do it would be to have a default associativity between different operators, but chains of the same operator can override it, e.g. suppose “⧺” means concatenation (rightward), “×” means repetition (leftward), and the default is leftward:

      [1, 2] ⧺  [3, 4] ⧺ [5, 6]   × 2  × 3
    (([1, 2] ⧺ ([3, 4] ⧺ [5, 6])) × 2) × 3

    [ [ [1…6], [1…6] ],
      [ [1…6], [1…6] ],
      [ [1…6], [1…6] ] ]
I dunno how good an idea that would be in practice, though.


Think exponentiation, where 2^3^4 might be 2^(3^4), but where subtraction 2-3-4 is (2-3)-4.


Consider:

  2-3^4


Since there is no precedence in this (hypothetical) language that would be an invalid expression.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: