News for hackers. Stuff that matters.
Re:Nimony (eventually Nim 3.0) Design Principles by umanwizard on Friday December 05, 2025 @09:48AM (#46162000)
What is the "even/odd theorem" ?
Re:Nimony (eventually Nim 3.0) Design Principles by ratmice on Friday December 05, 2025 @10:07AM (#46162252)
that all integers are either even or odd, and that for an even integer that integer + 1 and - 1 are odd and vice versa for odd numbers. That the negative numbers have an additional digit from the positive numbers ensures that low(integer) and high(integer) have different parity. So when you wrap around with overflow or underflow you continue to transition from an even to odd, or odd to even.
Re:Nimony (eventually Nim 3.0) Design Principles by xigoi on Friday December 05, 2025 @10:22AM (#46162454)
If you need wraparound, you should not use signed integers anyway, as that leads to undefined behavior.
Re:Nimony (eventually Nim 3.0) Design Principles by ratmice on Friday December 05, 2025 @10:31AM (#46162590)
Presumably since this language isn't C they can define it however they want to, for instance in rust std::i32::MIN.wrapping_sub(1) is a perfectly valid number.
Re:Nimony (eventually Nim 3.0) Design Principles by xigoi on Friday December 05, 2025 @10:36AM (#46162664)
Nim (the original one, not Nimony) compiles to C, so making basic types work differently from C would involve major performance costs.
Re:Nimony (eventually Nim 3.0) Design Principles by beagle3 on Friday December 05, 2025 @04:06PM (#46167307)
And yet, Nim does overflow checking by default.
Re:Nimony (eventually Nim 3.0) Design Principles by umanwizard on Friday December 05, 2025 @10:34AM (#46162632)
Signed overflow being UB (while unsigned is defined to wrap) is a quirk of C and C++ specifically, not some fundamental property of computing.
Re:Nimony (eventually Nim 3.0) Design Principles by Symmetry on Friday December 05, 2025 @11:06AM (#46163146)
Specifically, C comes form a world where allowing for machines that didn't use 2's compliment (or 8 bit bytes) was an active concern.
Re:Nimony (eventually Nim 3.0) Design Principles by aw1621107 on Friday December 05, 2025 @12:05PM (#46164051)
Interestingly, C23 and C++20 standardized 2's complement representation for signed integers but kept UB on signed overflow.
Re:Nimony (eventually Nim 3.0) Design Principles by Asooka on Friday December 05, 2025 @05:51PM (#46168448)
Back when those machines existed, UB meant "the precise behaviour is not specified by the standard, the specific compiler for the specific machine chooses what happens" rather than the modern "a well-formed program does not invoke UB". For what it is worth, I compile all my code with -fwrapv et. al.
Re:Nimony (eventually Nim 3.0) Design Principles by aw1621107 on Saturday December 06, 2025 @12:33AM (#46170993)
> UB meant "the precise behaviour is not specified by the standard, the specific compiler for the specific machine chooses what happens"

Isn't that implementation-defined behavior?

Re:Nimony (eventually Nim 3.0) Design Principles by xigoi on Friday December 05, 2025 @10:36AM (#46162672)
Nim (the original one, not Nimony) compiles to C, so making basic types work differently from C would involve major performance costs.
Re:Nimony (eventually Nim 3.0) Design Principles by ratmice on Friday December 05, 2025 @10:52AM (#46162921)
Presumably unsigned want to return errors too?

Edit: I guess they could get rid of a few numbers... Anyhow it isn't a philosophy that is going to get me to consider nimony for anything.

Re:Nimony (eventually Nim 3.0) Design Principles by umanwizard on Friday December 05, 2025 @10:47AM (#46162836)
> making basic types work differently from C would involve major performance costs.

Not if you compile with optimizations on. This C code:

  int wrapping_add_ints(int x, int y) {
      return (int)((unsigned)x + (unsigned)y);
  }
Compiles to this x86-64 assembly (with clang -O2):

  wrapping_add_ints:
          lea     eax, [rdi + rsi]
          ret
Which, for those who aren't familiar with x86 assembly, is just the normal instruction for adding two numbers with wrapping semantics.