I've been writing a few for loops in Julia and seen a few behaviours that
were surprising to me:
Firstly, it seems that using `in` is converted to `=` at some point in the
parser. This caught me out when looking at a macro that expanded to a for
loop.
julia> quote for x in y print(x) end end
quote # none, line 1:
for x = y # line 1:
print(x)
end
end
I'm also surprised that `for x in y` doesn't require a container:
julia> for x in 1 println(x) end
1
I would have expected an error in this case.
Finally, Julia seems to have a Perl-style array flattening:
julia> for row in [[1, 2], [3, 4]] println(row) end
1
2
3
4
I would have expected row to be bound to the subarrays, not the integers. I
can work around this with:
julia> for row in Array[[1, 2], [3, 4]] println(row) end
[1,2]
[3,4]
I'm not seeking to criticise, just to understand. What's the motivation
behind this behaviour?
Wilfred