var fact5 = (
var result = 1;
for i in 1..5:
result *= i;
result
)
Because inside an expression, indentation may not do what it normally does in a statement context. You'll have to add extra parentheses so that the compiler understands what you're doing:
var fact5 = (
var result = 1;
(for i in 1..5:
result *= i);
result
)
At this point, of course, you may just as well get rid of the indentation, since it won't do anything for you:
var fact5 = (var result = 1; (for i in 1..5: result *= i); result)
Ideally, I'd suggest not to try and make Nim's syntax do something that it wasn't meant to do. A template can do the same thing more cleanly:
template initVar(e: expr, s: stmt): stmt {.immediate.} =
var e = (block: s)
initVar fact5:
var result = 1
for i in 1..5:
result *= i
result
Or, alternatively, the following:
template eval(s: stmt): expr {.immediate.} =
(block: s)
var fact5 = eval do:
var result = 1
for i in 1..5:
result *= i
result