You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Julia Version 0.5.0 (2016-09-19 18:14 UTC) and noticed that in a comprehension you can't iterate over empty sequences unless that variable is the last one. (EDIT: I just tested in the binaries of the nightly builds and the same thing happens.)
I'd expect both of these comprehensions to result in empty arrays:
julia> [a for a in [1] for b in []]
0-element Array{Int64,1}
julia> [a for a in [] for b in [1]]
ERROR: ArgumentError: argument to Flatten must contain at least one iterator
instart(::Base.Flatten{Base.Generator{Array{Any,1},##193#195}}) at ./iterator.jl:599ingrow_to!(::Array{Any,1}, ::Base.Flatten{Base.Generator{Array{Any,1},##193#195}}) at ./array.jl:357incollect(::Base.Flatten{Base.Generator{Array{Any,1},##193#195}}) at ./array.jl:273
Or a list of triples (a,b,a+b) where 1<=a<b<5 and a+b is prime:
julia> [(a,b,c) for a=1:5for b=a+1:5for c in [a+b] ifisprime(c)]
ERROR: ArgumentError: argument to Flatten must contain at least one iterator
instart(::Base.Flatten{Base.Generator{UnitRange{Int64},##18#21{Int64}}}) at ./iterator.jl:599in next at ./iterator.jl:614 [inlined]
ingrow_to!(::Array{Tuple{Int64,Int64,Int64},1}, ::Base.Flatten{Base.Generator{UnitRange{Int64},##17#20}}, ::Tuple{Int64,Base.Flatten{Base.Generator{UnitRange{Int64},##18#21{Int64}}},Tuple{Int64,Base.Generator{Filter{#isprime,Array{Int64,1}},##19#22{Int64,Int64}},Tuple{Bool,Int64,Int64}}}) at ./array.jl:364ingrow_to!(::Array{Union{},1}, ::Base.Flatten{Base.Generator{UnitRange{Int64},##17#20}}, ::Tuple{Int64,Base.Flatten{Base.Generator{UnitRange{Int64},##18#21{Int64}}},Tuple{Int64,Base.Generator{Filter{#isprime,Array{Int64,1}},##19#22{Int64,Int64}},Tuple{Bool,Int64,Int64}}}) at ./array.jl:372ingrow_to!(::Array{Tuple{Int64,Int64,Int64},1}, ::Base.Flatten{Base.Generator{UnitRange{Int64},##17#20}}) at ./array.jl:357incollect(::Base.Flatten{Base.Generator{UnitRange{Int64},##17#20}}) at ./array.jl:273
Oops, that last value of a let to an empty range for b, better skip it:
julia> [(a,b,c) for a=1:4for b=a+1:5for c in [a+b] ifisprime(c)]
5-element Array{Tuple{Int64,Int64,Int64},1}:
(1,2,3)
(1,4,5)
(2,3,5)
(2,5,7)
(3,4,7)
The text was updated successfully, but these errors were encountered:
Sorry, it seems this is just a duplicate of #18852, where it is explained that this behavior is currently intentional as a hacky way of getting type stability.
I'm using Julia Version 0.5.0 (2016-09-19 18:14 UTC) and noticed that in a comprehension you can't iterate over empty sequences unless that variable is the last one. (EDIT: I just tested in the binaries of the nightly builds and the same thing happens.)
I'd expect both of these comprehensions to result in empty arrays:
Or a list of triples (a,b,a+b) where 1<=a<b<5 and a+b is prime:
Oops, that last value of
a
let to an empty range forb
, better skip it:The text was updated successfully, but these errors were encountered: