proc makeArray():seq[int]=
result= @ [1,2,3,4]
var ar=makeArray()
for a in ar: echo(a) #this works!
for a in makeArray(): echo(a) #this does not, why?
I agree it's confusing. :-/ I'll see what I can do to improve the situation. However, it's only a shortcut for an implicit 'items' invocation, so just use that as a workaround:
for a in items(makeArray()): echo a
More efficient though would be to turn the 'makeArray' into an iterator.
The spec says http://nimrod-code.org/manual.html#implict-items-pairs-invokations so that it's actually a bug. :-)
The underlying problem is that a for loop context makes the compiler expect an iterator and you give it a proc instead. makeArray() looks like an iterator invokation though so it does not rewrite that to items(makeArray(). The expression ar does not have this problem.