klmr / klmr/fun

`->` has a scoping bug

Open
#10 0 comments 0 reactions 1 assignee Claimed by @klmr View on GitHub
bug
Dominant language
R
Stars
19
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Needs investigation. The following two pieces of code should be equivalent but aren’t:

```r
lambda = function (x) {
mod::import('klmr/functional/lambda', '<-')
lapply(seq_along(x), i -> x[i])
}
```

```r
lambda2 = function (x) {
mod::import('klmr/functional/lambda', '<-') # For consistency with the above
lapply(seq_along(x), function (i) x[i])
}
```

Called as:

```r
lambda(1 : 5)
lambda(1 : 5)
```

The second implementation works as expected; the first works for the first time, but fails when called again with:

> Error in match.fun(FUN) : object 'i' not found

To make matters worse, the error vanishes when the function is being debugged. It *also* vanished if the `mod::import` call is pulled out of the function into the global namespace.

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.