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

Ellipsis expansion into arguments #49

Open
dgkf opened this issue Sep 6, 2023 · 3 comments · Fixed by #59
Open

Ellipsis expansion into arguments #49

dgkf opened this issue Sep 6, 2023 · 3 comments · Fixed by #59
Labels
meta-proposal Language proposals theme-internals Relates to internal operations of the language type-enhancement New feature or request

Comments

@dgkf
Copy link
Owner

dgkf commented Sep 6, 2023

The inverse of #48 is expanding into ellipsis.

I think this should use the same syntax as #48

args <- list(sep = "-", collapse = "; ")
paste("Hello", c("World", "Friends"), ..args)

I don't think there are situations where it's ambiguous. ..rest for collecting into arguments will only happen when destructuring or in a function signature, while ..rest for passing arguments only happens in calls. This might introduce some confusion in situations where the ..rest argument in a function signature is re-used as an argument to default value for another parameter:

f <- function(a, b = sum(..rest), ..rest)) {
}

In this case, the ..rest at the end of the function call collects args, while the ..rest in names(..rest) passes those arguments to sum.

@dgkf dgkf added type-enhancement New feature or request theme-internals Relates to internal operations of the language meta-proposal Language proposals labels Sep 6, 2023
@dgkf dgkf linked a pull request Oct 3, 2023 that will close this issue
@dgkf dgkf closed this as completed in #59 Oct 9, 2023
@dgkf
Copy link
Owner Author

dgkf commented Oct 10, 2023

Reopening, still room for discussion here

@dgkf dgkf reopened this Oct 10, 2023
@sebffischer
Copy link
Collaborator

sebffischer commented Oct 17, 2023

What is the motivation between the "Duplicated names okay, last instance takes priority"?

This seems to be something not unlikely to cause unintended behaviour / bugs.
I would argue that the f(..args, ..more_args) call in the lines below should behave just like f(a = 1, b = 2, c = 3, c = 10), i.e. result in an Error

args <- (a = 1, b = 2, c = 3)
f <- function(a, b, c) {
  a + b + c
}
more_args <- (c = 10)
f(..args, ..more_args) 

@sebffischer
Copy link
Collaborator

sebffischer commented Oct 17, 2023

Let's say I have the function f = function(...) Reduce(sum, list(...)) and I unintentionally call it with duplicated arguments (using the args and more_args definition from the post above): f(..args, ..more_args).
In that case I think it is preferable to return an error instead of silently ignoring the c element in the args vector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta-proposal Language proposals theme-internals Relates to internal operations of the language type-enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants