On many programming subreddits, there are arguments about using square
brackets[] for generics instead of the cumbersome angle<> brackets,
particularly in Rust and Go. The most common point brought up is that
expressions like `foo[x]()` would be ambiguous — is it a generic function call,
or a use of indexing followed by calling the result? However, Nim doesn't seem
to have a problem with this; the following code works as expected:
const zero = 0
let arrWithProc = [proc(): string = "Hello world!"]
echo arrWithProc[zero]()
func returnGenericArg[num: static int](): int = num
echo returnGenericArg[zero]()
Run
Output:
Hello world!
0
Run
So my question is, how is this possible in Nim? Could other languages take
inspiration from it, or does it depend on a feature of Nim that e.g. Rust and
Go don't have?