fun
fun copied to clipboard
`->` has a scoping bug
Needs investigation. The following two pieces of code should be equivalent but aren’t:
lambda = function (x) {
mod::import('klmr/functional/lambda', '<-')
lapply(seq_along(x), i -> x[i])
}
lambda2 = function (x) {
mod::import('klmr/functional/lambda', '<-') # For consistency with the above
lapply(seq_along(x), function (i) x[i])
}
Called as:
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.