[R] Inf and lazy evaluation

R. Michael Weylandt michael.weylandt at gmail.com
Tue May 15 07:25:57 CEST 2012


The only place I know lazy evaluation really is visible and widely
used is in the passing of function arguments. It's what allows magic
like

zz <- 1:5
plot(zz)

to know your variable was called "zz." It can also show up in some
places through the promise mechanism, but you have to do a little bit
of work to see them:

zz <- lapply(1:3, function(i) function(x) x^i)

zz[[2]](2)

Without lazy evaluation this would have been 4. Sometimes this winds
up hurting folks -- I'm not sure if it has a "good reason" to be there
or if its a consequence of lazy mechanisms elsewhere (which improve
overall performance)

But I don't believe R allows lazy constructors in any context.

Best,
Michael

On Mon, May 14, 2012 at 4:29 PM, J Toll <jctoll at gmail.com> wrote:
> Thank you all for the replies.
>
> On Mon, May 14, 2012 at 2:45 PM, R. Michael Weylandt
> <michael.weylandt at gmail.com> wrote:
>> R is lazy, but not quite that lazy ;-)
>
> Oh, what is this world coming to when you can't count on laziness to
> be lazy. ;)  I should probably stop reading about Haskell and their
> lazy way of doing things.
>
> As a relatively naive observation, in R, it seems like argument
> recycling kind of breaks the power of lazy evaluation.
>
> Thanks for the suggestion of list.files()
>
>
> James



More information about the R-help mailing list