Menu

#138 Space changes the behavior of implicit multiplication

v1.0 (example)
closed-fixed
nobody
None
5
2016-05-21
2013-02-08
Cousteau
No

I've noticed that adding a space between subexpressions changes the behavior of implicit multiplication.
`4 / 2(1+1)` is interpreted as `4 / (2 * (1+1))` since an implicit multiplication operator is inserted between the 2 and the (1+1), and such operator has higher precedence than division.
However, `4 / 2 (1+1)`, with a space between the 2 and the (1+1), is interpreted as `(4/2) * (1+1)`, so in this case implicit multiplication does NOT have higher precedence than division.
I think this behavior is weird since it doesn't follow the rule of "spaces are mostly ignored", and can be particularly annoying when using units, like `10 m / 5 s` returning `2 m*s` instead of `2 m/s`, forcing me to use `10m / 5s`. Maybe it's my fault for using a space there, but I'm used to separating quantities from units with a space.
I'm not sure if this behavior could be considered as a bug, but I think it's a bit counter-intuitive so I'm reporting it just in case.

It's also annoying that I can't use units like `10 m / 5 m/s` without using parentheses, but that doesn't seem easy to fix so I guess I'll have to get used to it.

Discussion

  • Hanna K.

    Hanna K. - 2016-05-21
    • status: open --> closed-fixed
    • Group: --> v1.0 (example)
     
  • Hanna K.

    Hanna K. - 2016-05-21

    Both "10 m / 5 s" and "10 m / 5 m/s" will be parsed according to your wishes in the default mode of the upcoming versions. Space will still not be ignored in the default mode, but a mode where space is ignored has been added, as well as one where implicit multiplication is parsed no differently from explicit multiplication.

     

Log in to post a comment.