zlacker

[return to "Nimony (Nim 3.0) Design Principles"]
1. kbd+4Hb[view] [source] 2025-12-05 13:01:54
>>andsoi+(OP)
The biggest thing I still don’t like about Nim is its imports:

    import std/errorcodes

    proc p(x: int) {.raises.} =
      if x < 0:
        raise ErrorCode.RangeError
      use x
I can’t stand that there’s no direct connection between the thing you import and the names that wind up in your namespace.
◧◩
2. xigoi+MHb[view] [source] 2025-12-05 13:06:07
>>kbd+4Hb
It needs to be this way so that UFCS works properly. Imagine if instead of "a,b".split(','), you had to write "a,b".(strutils.split)(',').
◧◩◪
3. poloti+6Jb[view] [source] 2025-12-05 13:14:32
>>xigoi+MHb
ok I do not understand.

What is preventing this import std/errorcodes

from allowing me to use: raise errorcodes.RangeError instead of what Nim has?

or even why not even "import std/ErrorCodes" and having the plural in ErrorCodes.RangeError I wouldn't mind

◧◩◪◨
4. PMunch+lKb[view] [source] 2025-12-05 13:21:49
>>poloti+6Jb
Nothing, and it fact this works. To move to an example which actually compiles:

    import math
    
    echo fcNormal
    echo FloatClass.fcNormal
    echo math.fcNormal
    echo math.FloatClass.fcNormal
All of these ways of identifying the `fcNormal` enum value works, with varying levels of specificity.

If instead you do `from math import nil` only the latter two work.

[go to top]