From jtalbot at stanford.edu  Fri Sep 30 18:26:53 2011
From: jtalbot at stanford.edu (Justin Talbot)
Date: Fri, 30 Sep 2011 09:26:53 -0700
Subject: [Rd] Language definition question - order of argument side effects
Message-ID: <CALLn38Myu=BTaj7h10vPh3qbprPG28p8E38OMsAgb5KhxONQbA@mail.gmail.com>

I'm interested in the difference between these two intuitively
equivalent sequences that produce different results (in R version
2.13.1 (2011-07-08) 32-bit). I think R's reference counting
optimization is causing this difference in behavior.

> a <- 1
> a+{a[1] <- 20}
[1] 21

> a <- 1
> a[1] <- 1
> a+{a[1] <- 20}
[1] 40

Is one of these the "correct" answer, or is the order of side effects
undefined in these statements? Section 4.3.3 of the R Language
Definition just says that doing assignment in an argument to a
function is "bad style", but doesn't say anything about evaluation
order.

In general, for primitive and internal functions, is a particular
evaluation order for the arguments guaranteed?

Thanks,
Justin Talbot



[Rd] Language definition question - order of argument side effects
Justin Talbot