Proposal: partial function evaluation
- Dominant language
- Rust
- Stars
- 145
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
It's very common to have a generic implementation of some behavior (for example, `mean()`, `vapply` or `dir.create`) and then want to wrap it to change some default (`mean(.., na.rm = TRUE)`, `vapply(.., FUN.VALUE = logical(1L))`, `dir.create(.., recursive = TRUE)`)
Currently, this is managed by wrapping these behaviors in a function. This syntax can be a bit tedious and adds extra layers to the call stack.
Instead, I think these behaviors might be well suited to partial function evaluation. Instead of `Promises` coming from the function call, they can be collected from multiple partial calls:
```r
vlapply <- vapply(..., FUN.VALUE = logical(1))
vlapply(1:10, as.logical)
```
The syntax of this needs to:
- Avoid conflicts with other uses of `...`, `..rest`
- Ideally, be easy to see at a glance, avoiding ambiguous reading of code as producing a return value as opposed to a function
### Proposals
Partial function. Probably the most canonical style. Uses R metaprogramming to return a partial function call object.
`partial(vapply(FUN.VALUE = logical(1)))`
Trailing comma. I don't like this one. A trailing comma is too convenient to have as optional syntax, too easy to accidentally introduce, and difficult to spot in long calls.
`vapply(FUN.VALUE = logical(1),)`
Dots suffix
`vapply(FUN.VALUE = logical(1))..`
Dots name suffix
`vapply..(FUN.VALUE = logical(1))`
"Rest" call (similar to rest args). Rest args are always lists, so there's no fear of rest args clashing with function calls.
`..vapply(FUN.VALUE = logical(1))`
---
I think `Primitive("partial")` might be a good first step, and I also like the `..fn()` syntactic sugar.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the proposal's examples and the existing handling of promises, partial calls, and `...`; the issue mentions `Primitive("partial")` and several possible syntaxes but no implementation files or tests. A contribution would first need an agreed syntax and semantics, followed by implementation and tests demonstrating the proposed partial function behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r, rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100