I am reading this paper (ungated copy) on evaluating the design of the R programming language, and am not able to understand a particular example on lexical scoping (or the absence thereof).
On page 4, the authors provide the following example of the use of the with function:
with(formaldehyde, carb*optden)
They go on to say:
The astute reader will have noticed that the above example clashes with our claim that R is lexically scoped. As is often the case, R is lexically scoped up to the point it is not. R is above all a dynamic language with full reflective access to the running program’s data and representation. In the above example, the implementation of with sidesteps lexical scoping by reflectively manipulating the environment. This is done by a combination of lazy evaluation, dynamic name lookup, and the ability turn code into text and back:
with.default <- function(env, expr, ...)
eval(substitute(expr),env, enclose=parent.frame())
The function uses
substituteto retrieve the unevaluated parse tree of its second argument, then evaluates it withevalin the environment constituted by composing the first argument with the lexically enclosing environment. The ‘...’ is used to discard any additional arguments.
How is the use of the with function in this case a violation of the principles of lexical scoping?