x = y = 5
is equivalent to x = (y = 5)
, because the assignment operators "group" right to left, which works. Meaning: assign 5 to y
, leaving the number 5; and then assign that 5 to x
.
This is not the same as (x = y) = 5
, which doesn't work! Meaning: assign the value of y
to x
, leaving the value of y
; and then assign 5 to, umm..., what exactly?
When you mix the different kinds of assignment operators, <-
binds tighter than =
. So x = y <- 5
is interpreted as x = (y <- 5)
, which is the case that makes sense.
Unfortunately, x <- y = 5
is interpreted as (x <- y) = 5
, which is the case that doesn't work!
See ?Syntax
and ?assignOps
for the precedence (binding) and grouping rules.