Hacker News new | ask | show | jobs
by forgotpwtomain 3288 days ago
Hmm, I find the auto-associativity to be a bit weird for example:

≫ 1/12 c

  1 / (12 × c)
   = 2.7797e-10 s/m
2 comments

Thank you very much for the feedback!

This is on purpose (see operator precedence rules: https://github.com/sharkdp/insect#reference). Implicit multiplication (without an explicit multiplication operator) has a higher precedence than division in order for something like this to work:

  tan(15cm/3m)

  = tan(15cm/(3m))
On the other hand, explicit multiplication has a lower precedence than division, so you would have to write "1/12*c". I agree that it can be confusing at times (that's why there is a pretty printer), but I don't want the language/parser to be whitespace-aware.
See how GNU units resolves this:

  1/10 m -> 0.1 / m
  1|10 m -> 0.1 m
  27 ^ 2/3 -> 243
  27 ^ 2|3 -> 9
You get the gist of it - a division operator with insane precedence.
Ha! That's a really neat idea. Thank you for sharing this. I'll consider adding it.
Apparently unit-less constants should bind stronger:

1/4 s - > (1/4) s

1 m / 4 s - > (1 m) / (4 s)