-
Notifications
You must be signed in to change notification settings - Fork 23
Add support for comprehensions with conditionals #132
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
Add support for comprehensions with conditionals #132
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #132 +/- ##
==========================================
+ Coverage 78.98% 79.82% +0.83%
==========================================
Files 6 6
Lines 671 674 +3
==========================================
+ Hits 530 538 +8
+ Misses 141 136 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
016e717
to
7e11769
Compare
Oh, this is great, thank you! With these recent contributions, please let me know if you would be amenable to being added to the maintainer team -- more volunteers would be much appreciated. Could you bump the version number in Project.toml? That way I can make an immediate relase Could you add this edge case to the tests as well, to make sure variables stored in the finite state machine are properly used?
|
Just an update, that test case exposed an issue which seems to do with Box-ing ( About being in the maintanence team: as the above paragraph points out, I'm still working out a lot of the details of how the package works, but I'm open to joining in and helping out in whatever ways I can. I've also had a brief look into #99 , so if/when I dive into that, I'll probably get a much better understanding of the package as a whole too. |
Ah, it's looking like this was an existing problem before this PR, there just wasn't any pre-existing test for this. Trying a similar test on current julia> @resumable function test_comprehension_state()
c = 1
@yield [i*c for i in 1:10]
c += 1
@yield [i*c for i in 1:10]
end
test_comprehension_state (generic function with 1 method)
julia> for n in test_comprehension_state()
@show n
end
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Core.Box
The function `convert` exists, but no method is defined for this combination of argument types.
Closest candidates are:
Core.Box(::Any)
@ Core boot.jl:434
convert(::Type{T}, ::T) where T
@ Base Base.jl:126
Stacktrace:
[1] setproperty!(x::var"##test_comprehension_state_FSMI#231"{var"#1#3", Core.Box, var"#2#4"}, f::Symbol, v::Int64)
@ Base ./Base.jl:52
[2] ##test_comprehension_state_FSMI#231
@ ~/repos/ResumableFunctions.jl/src/macro.jl:2 [inlined]
[3] ##test_comprehension_state_FSMI#231
@ ~/repos/ResumableFunctions.jl/src/macro.jl:213 [inlined]
[4] iterate (repeats 2 times)
@ ~/repos/ResumableFunctions.jl/src/types.jl:24 [inlined]
[5] top-level scope
@ ./REPL[4]:1 which is the same error. The existing tests for comprehensions all have So for now, I think the best course of action is to just bump the version in the Project.toml, and track the |
Thank you, that sounds great! Do you mind making the issue and putting |
You should have merge privileges now. I have reviewed this PR and I think it is a valuable improvement. Feel free to merge and release with |
This comment was marked as off-topic.
This comment was marked as off-topic.
7e11769
to
36f5caf
Compare
Comprehension support works by parsing the underlying generators, and generators with `if` conditions have `filter` as their `Expr` form's second argument. This previously wasn't supported, as the generator parsing code expected the `for` iteration's `=` to be the second arg instead. This change adds support for the case of generators with filters, and adds relevant tests.
36f5caf
to
e079107
Compare
Attempt to fix #129
Comprehension support works by parsing the underlying generators, and generators with
if
conditions havefilter
as theirExpr
form's second argument. This previously wasn't supported, as the generator parsing code expected thefor
iteration's=
to be the second arg instead.This change adds support for the case of generators with filters, and adds relevant tests.