Skip to content

Conversation

dgkf
Copy link
Owner

@dgkf dgkf commented Oct 3, 2023

Note

Feedback Wanted. This adds new syntax that might not add enough value over R's existing ... ellipsis arguments.
Let me know what you think!

New features

☑️ ..rest args which can be used to name a value for ellipsis arguments.

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

Ellipsis arguments are handled a bit different than R already, producing a list of unevaluated closures. The named arguments are no different, allowing them to be operated on as lists, and their values will only be forced when needed.

☑️ Using ..rest arguments in function calls

f(a, b, ..rest)

☑️ Allowing multiple ..rest args

In such cases, the last arg is accepted. This is to allow default values and masking values to be seamlessly combined without having to juggle argument uniqueness between unpacked rest values.

rest <- list(c = 10)
masking_rest <- list(c = 100)

f(a, b, ..rest, ..masking_rest) # equivalent to f(a, b, c = 100)

Future Work

Using ..rest in destructuring assignment

(a, ..rest) <- (1, 2, 3, 4)

Using anonymous .. to disregard additional elements during assignment

(a, ..) <- (1, 2, 3, 4)

Using anonymous .. "more" to partially evaluate a function

sum_nums <- sum(na.rm = TRUE, ..)   # assuming we hold on to the na.rm params... which feels unlikely to me
sum_nums([NA, 1, 2, 3])
# [1] 6

@dgkf dgkf linked an issue Oct 3, 2023 that may be closed by this pull request
@dgkf dgkf added theme-internals Relates to internal operations of the language type-design Discussion regarding design of enhancements or project at large meta-proposal Language proposals status-feedback-needed Needs further discussion before moving further labels Oct 3, 2023
@dgkf dgkf merged commit 3016eb3 into main Oct 9, 2023
@dgkf dgkf deleted the 49-rest-args branch October 9, 2023 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta-proposal Language proposals status-feedback-needed Needs further discussion before moving further theme-internals Relates to internal operations of the language type-design Discussion regarding design of enhancements or project at large
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ellipsis expansion into arguments
1 participant