New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"for z in zip()" doesn't terminate #43821
Comments
I'd say that the behavior of julia> for (_, x) in zip(zip(), 1:3) # this is like `0 + 3`
@show x
end
x = 1
x = 2
x = 3 From this point of view, the definition Ref: #35293 |
@tkf ehh... why would 99.9% of the users care if in fact there's a single (place) mention of "monoid" in the entire Julia base: julia/doc/src/manual/strings.md Lines 526 to 528 in df5b081
I'm not saying what you're saying is wrong / irrelevant, just asking from a typical user perspective. If you have a user of Julia asking (e.g. a grad student from not CS) "why does empty zip have infinite length", would you give them the above speech? |
Maybe a simpler grad-student ready explanation is " |
and what is |
Adding inputs can only make it stop sooner. This is the same kind of reasoning that explains julia> all(!isempty, Vector[])
true For the opposite behavior, see |
If this is a common error, perhaps we can make |
by this logic |
I'm 99% sure nobody actually relies on this producing infinite loop, we can fix this as a minor change in 1.x |
julia> collect(reduce(zip, [1:3, 4:6]; init=zip()))
3-element Vector{Tuple{Tuple{Tuple{}, Int64}, Int64}}:
(((), 1), 4)
(((), 2), 5)
(((), 3), 6) This code seems fine to me, I wouldn't try to ban it. |
Feel free to make a PR; we can check with PkgEval. |
`zip(xss...)` terminates when its shortest argument does -- the initial case is infinite. JuliaLang#43821 (comment)
I've added a PR to document the behavior. This change will reduce the risk of surprise, while retaining the composability. |
Is C++ viewed::zip a zip? |
`zip(xss...)` terminates when its shortest argument does -- the initial case is infinite. #43821 (comment)
is an infinite loop, printing
z = ()
over and over.Arguably, it should execute once with
z = ()
, or maybe throw an error, or maybe execute zero times (like Python), but in any case the current behavior seems bad.The text was updated successfully, but these errors were encountered: