It would be nice to be able to do the following without the UndefVarError:
julia> reduce(+, 1 for i in 1:2, j in i:3; init = 0)
ERROR: UndefVarError: i not defined
Stacktrace:
[1] top-level scope at none:1
julia> sum(1 for i in 1:2, j in i:3)
ERROR: UndefVarError: i not defined
Stacktrace:
[1] top-level scope at none:1
I understand you can workaround it using if statements:
julia> sum(1 for i in 1:2, j in 1:3 if j>=i)
5
but it would be nice to not have to do it this way…
Having iterators depend on other iterators works with standard for loops:
julia> for i in 1:2, j in i:3
1
end
It would also be great if you could create sparse arrays using similar notation:
julia> [1 for i in 1:2, j in i:3]
ERROR: UndefVarError: i not defined
Stacktrace:
[1] top-level scope at none:1
That makes sense. It would be nice if it made a sparse matrix when needed so that you could use it in a more straightforward fashion in sum or reduce as is done when creating variable arrays in JuMP: