Non-Intrusive Migration from Lazy to Eager Evaluation
In this talk, I will present our motivation and attempt to non-intrusively migrate the R ecosystem from lazy to eager evaluation. R is a lazy programming language. Lazy evaluation strategy delays an expression’s evaluation by wrapping it in a thunk, evaluates it only when needed, and, caches the result for reuse. Among its key benefits, laziness avoids the computation of redundant expressions and facilitates modular program construction through lazy data structures. However, laziness in R was not added for these reasons, but to enable metaprogramming by allowing argument text to be reflectively accessed from a thunk for modification and dynamic evaluation in a custom environment. By design, R is only “weakly” lazy. Only argument evaluation of user-defined functions is delayed; all other expressions are evaluated eagerly. Most built-in functions are strict in their arguments. Built-in data types such as arrays are strict for interoperability with native math libraries. While lazy languages such as Haskell have carefully avoided mixing side-effects and laziness, R freely mixes side-effecting constructs with lazy evaluation, complicating code comprehension and defeating the modularity facilitated by lazy evaluation.