Skip to content
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

Feature request: kwarg defaults in terms of destructured argument names #41555

Open
pablosanjose opened this issue Jul 12, 2021 · 1 comment
Open
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Comments

@pablosanjose
Copy link
Contributor

pablosanjose commented Jul 12, 2021

We cannot currently combine positional-argument-destructuring and kwarg-with-defaults-in-terms-of-arguments. Namely, this works

f(x; y = x) = (x, y)

but this doesn't

julia> g((x, x´); y = x) = (x,y)
g (generic function with 1 method)

julia> g((2, 2))
ERROR: UndefVarError: x not defined

I have needed this functionality today, and I think it makes sense to provide it. The use case was something like this

function process_filtered_pairs((xs, ys); xmin = minimum(xs), xmax = maximum(xs))
    pairs = [(x, y) for (x, y) in zip(xs, ys) if xmin <= x <= xmax]
    # process pairs
end
@JeffBezanson JeffBezanson added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Jul 12, 2021
@JeffBezanson
Copy link
Member

Yes I'm pretty sure this should work. Seems like a lowering pass ordering kind of issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

No branches or pull requests

2 participants