Skip to content
Back to formatted view

Raw Message

Message-ID: <971536df0901190945r11eb9c66g1be35fe66053f6fa@mail.gmail.com>
Date: 2009-01-19T17:45:30Z
From: Gabor Grothendieck
Subject: lazy evaluation question
In-Reply-To: <4974BB1C.8020402@biostat.ku.dk>

On Mon, Jan 19, 2009 at 12:40 PM, Peter Dalgaard
<p.dalgaard at biostat.ku.dk> wrote:
> Gabor Grothendieck wrote:
>>
>> Note that
>>
>> rm(i)
>> for(j in 1:4) F(j)
>>
>> raises an error due to scoping issues.
>
> Yes. This has nothing to do with lazy evaluation, and everything to do with
> scoping: f is not defined in the scope of F, so does not know about its
> variables (nor those in the implicit loop of lapply()).
>
> Notice also that in
>
> lapply(1:4,function(i) F(i))
>
> it would be pretty weird if lapply would behave differently depending on the
> name of formal arguments of the function, i.e. if
>
> lapply(1:4,function(meep) F(meep))
>
> gave a different result. And f() depends on looking for a variable i outside
> of the function.


I believe that is what I was already referring to when I referred to
"scoping issues".
Since "not works" was never defined in the original post its hard to
know what the
problem being asked is but it might have been confusion over the
different uses of i.