Hi everyone,
Why does the following compile:
import future
echo lc[x+2 | (x <- 1..10), int]
to give
@[3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
but
import future
echo lc[x^2 | (x <- 1..10), int]
gives a compilation error:
Error: type mismatch: got (int, int literal(2))
but expected one of:
proc `^`(x: int): int
proc `^`[T](x: int; y: openArray[T]): int
> Process terminated with exit code 1
The problem is that ^ is not a binary operator in Nim, but used with array indexing to index the n-th element from the end (e.g. a[^1]).
If you want to square x, use:
echo lc[x*x | (x <- 1..10), int]
If you want xor (i.e. the semantics of ^ in C/C++), use:
echo lc[x xor 2 | (x <- 1..10), int]