Underscores.jl
Underscores.jl copied to clipboard
Underscore placeholders for convenient closure syntax
I am not sure whether extra care should be taken when we allow Expr(:quot) to be recursed into, but this fixes the issue.
Currently `@_ a |> f(_, b)` is needed but in other tools like Lazy.jl and R's magrittr which allows the first argument to be the previous one without `_` e.g....
We've had a couple of specific cases where `_` expansion is confusing - opened in #6 and #8 and solved by #10. But because #10 is breaking, I'd like to...
This allows a single `_` to be treated as the slot into which the closure created by do syntax is inserted. It's somewhat overloaded in that `@_ map(_, xs)` normally...
Something which ought to work, I think: ```julia mutable struct Bar x end; bars = [Bar(i) for i in 1:3]; @_ map(_.x, bars) # fine @_ foreach(_.x = 2, bars)...
One leftover commit from #10, may or may not be the ideal behaviour. Needs tests. New discussion is #12.
WIP - still needs tests + docs It's also unclear whether this is a desired behavior. I feel like — though this could be rather useful — it's strangely inconsistent...
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...
`Expr(:quote)` is actually a quasiquote, so the following should be equivalent: ```julia julia> map(i->:(a[$i]), 1:4) 4-element Array{Expr,1}: :(a[1]) :(a[2]) :(a[3]) :(a[4]) julia> @_ map(:(a[$_]), 1:4) ERROR: syntax: all-underscore identifier used...