From simon.urbanek at r-project.org  Fri Dec 27 05:57:44 2013
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 26 Dec 2013 23:57:44 -0500
Subject: [Rd] RHS of assignment is evaluated eagerly?
In-Reply-To: <CAJoaRhZY4_scgDmCP3244-WHDQwFBqzQPH_hFz5AsAWhJAc6sw@mail.gmail.com>
References: <CAJoaRhZY4_scgDmCP3244-WHDQwFBqzQPH_hFz5AsAWhJAc6sw@mail.gmail.com>
Message-ID: <9AE5940B-3A40-4365-9AD0-D7B5026FBD23@r-project.org>

On Dec 26, 2013, at 10:26 PM, Peter Meilstrup <peter.meilstrup at gmail.com> wrote:

> 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?
> 

?Use the source, Luke?:

    /*  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



[Rd] RHS of assignment is evaluated eagerly?
Simon Urbanek