dgkf / dgkf/R

Use binary `?` operator as `try-else`

Open
#52 2 comments 0 reactions 0 assignees View on GitHub
meta-proposal theme-internals type-enhancement
Dominant language
Rust
Stars
145
Forks
5
PR merge metrics
No merged PRs in 30d

Description

R's error propagation is already quite powerful! All expressions are evaluated as though they can fail, and their errors are reported up through the call stack.

However, R's error capture and recovery is a bit messier. Instead of throwing errors, many codebases resort to returning `NULL` or some other value of significance to indicate an error, which can be interpreted as a special case by the calling function. This seems to be a pattern that has arisen out of the clunky error handling.

Perhaps we can make code both more readable and more stable by introducing better error handling features:

```r
f <- function() {
x <- g(x) ? g_default()
paste0(x, "World")
}
```

The R world has no shortage of infix operators floating around, so deciding to reuse the binary infix behavior of a symbol should be done cautiously to make the best use of the syntax.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.