discard """ output: '''108 11 -1 1936 0.4 true truefalse''' """ proc `++`(x: var int; y: int = 1; z: int = 0) = x = x + y + z var g = 70 ++g g ++ 7 g.`++`(10, 20) echo g #let lv = stdin.readline #var vv = stdin.readline #vv = "abc" # valid, reassignment allowed #lv = "abc" # fails at compile time #proc square(x: int): int = x*x template square(x: int): int = # ensure 'x' is only evaluated once: let y = x y * y proc mostSignificantBit(n: int): int = # naive algorithm: var n = n while n != 0: n = n shr 1 result += 1 result -= 1 const msb3999 = mostSignificantBit(3999) echo msb3999, " ", mostSignificantBit(0), " ", square(44) proc filter[T](a: openarray[T], predicate: proc (x: T): bool): seq[T] = result = @[] # @[] constructs the empty seq for x in a: if predicate(x): result.add(x) proc map[T, S](a: openarray[T], fn: proc (x: T): S): seq[S] = newSeq(result, a.len) for i in 0 ..