Comments (3)
There are a couple of issues here involving using macros within @resumable
. Usually, a quick fix would be to have @resumable
call macroexpand
on the expression before rewriting things. The problem with that is that there's not actually a working @yield
anywhere. In a way, it's not really a macro, more of a syntactic indicator the rewrite engine looks at. So macroexpand
will see a @yield
and get very confused.
But I think a PR adding something like this could work:
function expand(M, ex::Expr)
head = ex.head
args = ex.args
if head == :macrocall && args[1] != Symbol("@yield")
return expand(M, macroexpand(M, ex; recursive=false))
else
newargs = map(Base.Fix1(expand, M), ex.args)
return Expr(ex.head, newargs...)
end
end
expand(M, s) = s
With your example, you'd then get
julia> macro yieldmany(resumable::Expr)
return quote
for x in $(esc(resumable))
@yield x
end
end
end
@yieldmany
julia> ex = quote
function F2()
@yield 2
@yieldmany F1()
@yield 4
end
end;
julia> expand(Main, ex)
quote
#= REPL[174]:2 =#
function F2()
#= REPL[174]:2 =#
#= REPL[174]:3 =#
#= REPL[174]:3 =# @yield 2
#= REPL[174]:4 =#
begin
#= REPL[173]:3 =#
for var"#889#x" = F1()
#= REPL[173]:4 =#
#= REPL[173]:4 =# @yield x
#= REPL[173]:5 =#
end
end
#= REPL[174]:5 =#
#= REPL[174]:5 =# @yield 4
end
end
It's not quite right - the variables in the for
loop got mixed up - but I think something along these lines could be made to work.
from resumablefunctions.jl.
When i write it out manually, things work as expected:
@resumable function F2()
@yield 2
for i in F1()
@yield i
end
@yield 4
end
julia> collect(F2())
4-element Array{Any,1}:
2
1
3
4
from resumablefunctions.jl.
What is F1
? I've seen weird things happen when trying to call macros inside a quote block (https://discourse.julialang.org/t/error-handling-in-quote-block-using-jump/79362/3?u=hdperez). I would discourage doing this.
from resumablefunctions.jl.
Related Issues (20)
- Resumable function has stopped HOT 2
- `continue` results in infinite loops HOT 3
- macro clashing with ProgressLogging.jl HOT 1
- is this package being maintained? HOT 5
- The CI/CD build is broken HOT 1
- Broken on Julia 1.10 (fix included) HOT 17
- Release v1.0.0? HOT 3
- CI, TagBot, Documenter fixes HOT 1
- a resumable function as a struct field var causes an error "struct expression not at top level"
- How to build fast iterators? HOT 4
- `@resumable` breaks blocks scope HOT 2
- let blocks without variable assignement like `let i; f(i); end` are not supported HOT 1
- significant regression in benchmarks HOT 4
- Functionals that refer to themselves are not supported (because they are not saved to the finite state machine)
- ResumableFunctions v0.6.6 StackOverflow with julia-1.10 HOT 8
- tests for downstream breakage HOT 1
- 0.6.7 breaks resumables with multiple fors over same variable HOT 6
- enable inference in self-referencing resumable functions
- named tuple syntax breaks `@resumable`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resumablefunctions.jl.