# (x,y) .+= z

**URL:** <https://discourse.julialang.org/t/x-y-z/5696>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 3, 2017, 4:55pm UTC](https://discourse.julialang.org/t/x-y-z/5696 "2017-09-03T16:55:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [September 3, 2017, 4:55pm UTC](https://discourse.julialang.org/t/x-y-z/5696/1 "2017-09-03T16:55:42Z")

</div>

The following example does not work:

```julia
x = y = 0.
x, y .+= 2.

```

I’d expect this to add 2 to `x` and `y`, but instead it throws an error.

Is there a reason for this?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 3, 2017, 8:25pm UTC](https://discourse.julialang.org/t/x-y-z/5696/2 "2017-09-03T20:25:47Z")

</div>

`.+=` is equivalent to a `broadcast!` call, but you can’t `broadcast!` to a tuple because tuples are immutable.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 3, 2017, 9:23pm UTC](https://discourse.julialang.org/t/x-y-z/5696/3 "2017-09-03T21:23:59Z")

</div>

That makes sense, of course, but what makes you expect the behaviour to work is that you can assign to a tuple (`x,y = 2,2`) even though it is immutable. I guess this could be considered similar (irrespective of the technical argument)?

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [September 3, 2017, 9:30pm UTC](https://discourse.julialang.org/t/x-y-z/5696/4 "2017-09-03T21:30:13Z")

</div>

Precisely, I was just about to say something like that.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 4, 2017, 9:51am UTC](https://discourse.julialang.org/t/x-y-z/5696/5 "2017-09-04T09:51:28Z")

</div>

What do you mean “assign to a tuple”. You are just creating a tuple there with two expressions (that happen to also initialize two variables).

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 4, 2017, 10:12am UTC](https://discourse.julialang.org/t/x-y-z/5696/6 "2017-09-04T10:12:43Z")

</div>

Not sure I follow? Could you explain a bit more? I read the expression as `(x, y) = (2,2)` (that also parses). To my view, that’s a tuple on the LHS. Do you mean this parses to `(x = 2, y = 2)`, i.e. a tuple of two expressions? (I mean I’m sure it does in the inside, but that’s not visible to the user).  
This works as expected: `x,y = (x, y) .+ 2` .

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 4, 2017, 10:30am UTC](https://discourse.julialang.org/t/x-y-z/5696/7 "2017-09-04T10:30:43Z")

</div>

> [@mkborregaard](#):
>
> Do you mean this parses to (x = 2, y = 2)

Wow, I am sure that is what you wrote in your post… You didn’t edit it, hehe? Actually, I see now that assignments aren’t even allowed inside a tuple…

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 4, 2017, 10:45am UTC](https://discourse.julialang.org/t/x-y-z/5696/8 "2017-09-04T10:45:00Z")

</div>

No edits, promise 🙂
