English 中文(简体)
在R中,我能找到与zy论点相关的环境?
原标题:In R can I find the environment associated with a lazy argument?

令人感到担心的是,这种情况非常复杂。

我想谈谈一个论点,但也知道应当对其加以评价的环境。 与此类似:

make.promise = function(x = print(b), b = 7) {
    expr = substitute(x)
    env  = parent.frame()

    function() {
        eval(expr, env)
    }
}

p1 = (
    function() {
        a = 2
        make.promise(print(a))
    }
)()

p2 = make.promise()

The problem is, if no argument is supplied for x, its environment becomes the local environment of make.promise(), and I don t know how to detect that. Is there a function other than substitute I could use that also captures the environment?

问题回答

<代码>make.promise的简单实施 将:

make.promise <- function(x) {
    function() x
}

但是,我不认为你重新寻找的东西。 我不知道找到相关环境的任何途径——你可以尝试通过电子邮件传送邮件清单。





相关问题
Closure/scope JavaScript/jQuery

I m trying to group some exisiting top-level functions inside a closure (to avoid polluting the global namespace) but I m not quite getting it to work. First, all the JS works outside my anonymous ...

Nested Lambdas in Python

I m a beginning python programmer, and I d like someone to clarify the following behavior. I have the following code: env = lambda id: -1 def add(id, val, myenv): return lambda x: val if x == ...

closures mean fully type-safe criteria?

combining closures (FCM) and generics, would it be possible to have fully type-safe criteria. // The following works without a cast as Foo.id is a long field. List<Long> ids = session....

Is nested XMLHttpRequests with multiple closures a good idea?

I have a Greasemonkey script which operates on a search results page at a video site. The function of the script is to take a javascript link that opens a new window with a flash player, jump through ...

How|Where are closed-over variables stored?

This is a question based on the article "Closing over the loop variable considered harmful" by Eric Lippert. It is a good read, Eric explains why after this piece of code all funcs will return the ...

Scope with a self-invoking function in Javascript

Take below code iterates over 6 input buttons and attaches an onclick event to every button that alerts the index number of the respective iteration: for (var i = 1; i < 6; ++i) { var but = ...

热门标签