[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-devel
Subject:    Re: [Rd] RHS of assignment is evaluated eagerly?
From:       Simon Urbanek <simon.urbanek () r-project ! org>
Date:       2013-12-27 4:57:44
Message-ID: 9AE5940B-3A40-4365-9AD0-D7B5026FBD23 () r-project ! org
[Download RAW message or body]

On Dec 26, 2013, at 10:26 PM, Peter Meilstrup <peter.meilstrup@gmail.com> w=
rote:

> Is this expected behavior, and if so, why? I would have expected
> neither 'arg' nor 'value' to evaluate until forced.
> =

> `test<-` <- function(obj, arg, value) {
>  1 #force no args
> }
> x <- 1
> test(x, print("evaled arg")) <- print("evaluated value")
> =

> ## [1] "evaluated value=94
> =


=93Use the source, Luke=94:

    /*  It's important that the rhs get evaluated first because            =
                                                           =

        assignment is right associative i.e.  a <- b <- c is parsed as     =
                                                           =

        a <- (b <- c).  */

Compare to

> `test<-`(x, print("evaled arg"), print("evaluated value"))
[1] 1

Cheers,
Simon

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic