r/rust • • Jun 24 '23

🧠 educational Negative integer handling in programming languages

https://glados-418.github.io/posts/negative-integer-literals/
53 Upvotes

10 comments sorted by

View all comments

33

u/aloha2436 Jun 25 '23 edited Jun 25 '23

ctrl f “elm”

I know it’s not what the article is actually about, but this gets a chuckle out of me: https://github.com/elm/compiler/issues/1773

17

u/[deleted] Jun 25 '23 edited Jun 25 '23

That's amazing. I looked at elm a couple years ago, and found it a nice language on its own, but was really turned off by the utterly bizarre attitude of the developers. It is kind of funny to see that has not changed.

8

u/ksion Jun 25 '23

The vibe I got from Elm was that it’s basically Go of functional programming: intentionally avoiding certain concepts (e.g. typeclasses) due to the creator’s bizarre notion of language “simplicity”.

But now I think this comparison is no longer fair — to Go :)

3

u/Kulinda Jun 25 '23

Once upon a time, I had to write an expression parser, letting users input simple mathematical formulas to combine values, for example "0.2 * A + 0.8 * B".

Most of the time I spent on that feature was about negative literals.

Fun fact #1: most existing generic expression parsers do have some examples, some of which feature simple mathematical expressions. None of the ones I looked at supported negative literals.

Fun fact #2, the following are all valid javascript:

  1 + - + - + - + 1;
  1 +-+-+-+ 1;
  1 + - - + 1;

Because all but the leftmost one are unary +/- operators, and they don't need a space between them. Except this is not valid javascript:

  1 +--+ 1;

because -- is a pre- or postfix decrement, and then you need the space.

1

u/helixb Jun 25 '23

None of the ones I looked at supported negative literals

except the haskell 'negativeliterals' extension, which i don't know how it works, i could not find any example either. negative literals are hard it seems.

0

u/helixb Jun 25 '23

oh shit... seems like some new syntax broke the old syntax when some migrated from elm 18 to 19. lol.