On Sunday, September 7, 2014 6:00:55 AM UTC-5, [email protected] wrote: > > 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. >
`in` is equivalent to `=`, yes. This just makes iteration nicer to read. > I'm also surprised that `for x in y` doesn't require a container: > > julia> for x in 1 println(x) end > 1 > It's both less bad and weirder than that. Integers are iterable. You can search through the list; either Jeff or Stefan has talked about this at some point. > I would have expected an error in this case. > If integers weren't iterable, that would be reasonable. > Finally, Julia seems to have a Perl-style array flattening: > More precisely, it's MATLAB-style array concatenation. Fine if you're used to it (hi), annoying if you're not. It'll probably go away, but figuring out how to make it go away has proven nontrivial. See: https://github.com/JuliaLang/julia/issues/2488 https://github.com/JuliaLang/julia/issues/3737 https://github.com/JuliaLang/julia/issues/7941 https://github.com/JuliaLang/julia/pull/7998 Patrick
