-
Notifications
You must be signed in to change notification settings - Fork 3
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
Consider capturing bindings by value (FastClosures.jl) #11
Comments
BTW, I created https://github.com/tkf/UnderscoreOh.jl which lets you create capture-by-value closures with super ad-hoc syntax like Maybe it also helps if you disallow "statements" in |
That would be safe but it also seems a little unfortunate given that things like Note that I'm super ok with breaking changes for this package, because there are still several usability problems (#6 / #8) which must be worked out and will be breaking. It appears I was too keen to release version 1.0, but oh well! Overall the main thing I'm concerned with here is iterating toward the most sensible semantics which could be absorbed into |
I wonder whether there's some It would be fine IMO to disallow function foo()
y = 1
@_ map((y=_^2; y^2), [1,2,3])
y
end But the following pure version should be fine function foo()
@_ map((y=_^2; y^2), [1,2,3])
end as should a version where function foo()
@_ map((y=_^2; y^2), [1,2,3])
end We've got |
... maybe, it would be occasionally useful to have "macros" which act on desugared ASTs as well as ones which act on the surface syntax. |
Right. I think I agree. (The hesitancy bit is that I'm still not sure how complex the underscore form anonymous should "allowed" to be.)
Yes! It'd be super useful for something like FLoops.jl. I guess there is a kind of chicken-and-egg problem since you can't get to the desugared AST without expanding the macro... I guess it's already possible if you let the macro see the entire function: @_ function foo()
map((y=_^2; y^2), [1,2,3])
end Then, you can analyze the scope using JuliaVariables.jl. Or, it'd be even better if For more restricted and composable API, maybe it's nice to have an API macro @_(expr)
:(@generatewith process_underscores $(esc(expr)))
end with |
As was briefly mentioned on on Zulip https://julialang.zulipchat.com/#narrow/stream/235161-compiler-frontend/topic/capture-by-value.20closures.3F.20(lowering.20in.20Julia) it might be useful if all
_
-based closures captured a separate binding.Alas this would departs in significant but very subtle ways from the lexical scoping of the language which is not great. But on the upside it could be considered because
_
syntax is for very short expressions and one wouldn't normally want to mutate the bindings captured within_
syntax is for calling higher order functions, and in typical uses it would be unusual for the lifetime of the closure to outlive the function it's passed to.CC @tkf
The text was updated successfully, but these errors were encountered: