4 ms·
R does have call-by-need semantics, like (an impure) Haskell, but that's not why replicate's second argument gets evaluated multiple times: replicate <- func
by bedatadriven 15y ago
R does have call-by-need semantics, like (an impure) Haskell, but that's not why replicate's second argument gets evaluated multiple times:
replicate <- function (n, expr, simplify = TRUE)
sapply(integer(n),
eval.parent(
substitute(function(...) expr)),
simplify = simplify)
The replicate function uses R's compute-on-the-language to construct a new function that has expr as its body.
A closure's argument will be evaluated at most once.
- deleted 15y ago[deleted]