Hacker News new | ask | show | jobs
by cb321 925 days ago
There may be compensating syntactic factors in the large to English word bitwise & boolean operators in the small -- such as being able to skip parentheses in command-style function call syntax and define your own operators (to bring back brevity surgically) that are even implemented as templates or macros. Maybe you can have it all? { famous last words when trade-offs rear their heads :-) }. Personally, whenever I switch from Nim to any other PL (except maybe Unix shell) things always feel much more verbose.

EDIT: For example, say you want Python's Walrus operator. You can just do this (although you can often just use a slightly more verbose parenthesized `let` expression):

    proc `:=`*[T](x: var T, y: T): T = (x = y; x)
or maybe you want `myvar |= flag` like in C/Python. You can also do that:

    proc `|=`*[T, U](a: var T, b: U) = (a = a or b)
But both of those could also be templates or macros that get the whole AST, can pick the AST apart, and emit whatever Nim code you actually want.

In fact, since Nim has nicely nested scopes & hygienic templates, you can define a bunch of operators in a library `template`, called say `unsafePtrArith` for pointer arithmetic, import that and then make them available in a little sub-scope to your code like:

    unsafePtrArith: a += 5
or

    unsafePtrArith:
      b += 4
      c += 3