# Unexpected result from short-circuiting (inline if)

**URL:** <https://discourse.julialang.org/t/unexpected-result-from-short-circuiting-inline-if/94400>\
**Category:** General Usage\
**Created:** [February 10, 2023, 8:57am UTC](https://discourse.julialang.org/t/unexpected-result-from-short-circuiting-inline-if/94400 "2023-02-10T08:57:08Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [February 10, 2023, 9:18am UTC](https://discourse.julialang.org/t/unexpected-result-from-short-circuiting-inline-if/94400/3 "2023-02-10T09:18:32Z")

</div>

This looks like a nice one to add to [Syntax Surprises](https://discourse.julialang.org/t/syntax-surprises/92369).

Observe:

```julia
julia> a = 1, 2
(1, 2)

julia> a = (1, 2)
(1, 2)

julia> (a = (1, 2))
(1, 2)

julia> (a = 1, 2)
ERROR: syntax: invalid named tuple element "2" around REPL[228]:1

```

The basic idea is: in most circumstances, you should expect to have to wrap `Tuple`s in parentheses; excluding the parentheses for standalone assignment statements is the _exception_, not the rule.

Within parentheses, `=` binds more tightly than comma—this allows `NamedTuple`s to be formed. Namely, we get to make these:

```julia
julia> (a=1, b=2)
(a = 1, b = 2)

```

But, it comes with the drawback of somewhat unintuitive parsing rules, where the binding tightness of `=` depends on whether it’s wrapped in parentheses or not.

To illustrate how this influences your case:

```julia
julia> b = [0, 0];

julia> if true; b .= (1, 2) end; b
2-element Vector{Int64}:
 1
 2

julia> true && (b .= 1, 2)
([1, 1], 2)

julia> b
2-element Vector{Int64}:
 1
 1

julia> true && (b .= (1, 2)); b
2-element Vector{Int64}:
 1
 2

```

---

_[View the full topic](https://discourse.julialang.org/t/unexpected-result-from-short-circuiting-inline-if/94400)._
