That goes in the right direction. I think the body of the first map
can be moved to a resolve_kw
function and that function can be reused in the second map
. This way fancy cases like (;a=1, b, more...)
are handled better.
I just noticed that AtBackslash.jl (my unregistered package) already supports it:
julia> using AtBackslash
julia> f(; kwargs...) = (; kwargs...)
f (generic function with 1 method)
julia> let x = 1
# input `()` is ignored
() |> @\ f(; x)
end
(x = 1,)
julia> (x = 1, y = 2) |> @\ f(; :x, a = :y) # more real-world usecase
(x = 1, a = 2)
(This is only relevant for anonymous functions, though.)
Julia’s AST is very well-designed so that you can accidentally implement features
6 Likes
https://github.com/jw3126/EponymKeywordSyntax.jl
Registration is in progress.
5 Likes
This is implemented in the language itself, since v1.5:
4 Likes