# Question mark with dot operations

**URL:** <https://discourse.julialang.org/t/question-mark-with-dot-operations/99758>\
**Category:** General Usage\
**Created:** [June 2, 2023, 8:52am UTC](https://discourse.julialang.org/t/question-mark-with-dot-operations/99758 "2023-06-02T08:52:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Betristor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/betristor/32/45264_2.png) [@Betristor](https://discourse.julialang.org/u/Betristor)\
**Post date:** [June 2, 2023, 8:52am UTC](https://discourse.julialang.org/t/question-mark-with-dot-operations/99758/1 "2023-06-02T08:52:29Z")

</div>

I got such an example which quite confused me.

```julia
## Won't work
a = [1,2,3]
a .+= (true) ? [1,1,1] : 0
## Functionable version
a = [1,2,3]
b = (true) ? [1,1,1] : 0
a .+= b

```

The first version will report

```julia
ERROR: TypeError: non-boolean (Vector{Int64}) used in boolean context
Stacktrace:
 [1] top-level scope
   @ REPL[10]:1

```

but the second will work just fine.

I do regard it confusing that it doesn’t recognize `(true) ? [1,1,1] : 0` as a whole part when used in an anonymous way.

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [June 2, 2023, 9:04am UTC](https://discourse.julialang.org/t/question-mark-with-dot-operations/99758/2 "2023-06-02T09:04:43Z")

</div>

> [@Betristor](#):
>
> I got such an example which quite confused me.
> 
> ```julia
> ## Won't work
> a = [1,2,3]
> a .+= (true) ? [1,1,1] : 0
> ## Functionable version
> a = [1,2,3]
> b = (true) ? [1,1,1] : 0
> a .+= b
> 
> ```

Both versions work for me when running on Julia v1.9.0.  
Which version are you on?

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [June 2, 2023, 9:09am UTC](https://discourse.julialang.org/t/question-mark-with-dot-operations/99758/3 "2023-06-02T09:09:21Z")

</div>

Based on the reported error, I would guess that the broadcasting gets higher precedence than the ternary operator and the expression is evaluated as

```julia
(a .+= (true)) ? [1,1,1] : 0

```

You could try

```julia
a .+= ((true) ? [1,1,1] : 0)

```

However, I confirm that the original expression works for me on 1.9 too.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 2, 2023, 9:56am UTC](https://discourse.julialang.org/t/question-mark-with-dot-operations/99758/4 "2023-06-02T09:56:29Z")

</div>

I have tried on Julia 1.0.4 and 0.7 (the lowest version I have) and the first example also works…

---

<div class="post-metadata">

**Author:** ![Betristor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/betristor/32/45264_2.png) [@Betristor](https://discourse.julialang.org/u/Betristor)\
**Post date:** [June 2, 2023, 2:24pm UTC](https://discourse.julialang.org/t/question-mark-with-dot-operations/99758/5 "2023-06-02T14:24:54Z")

</div>

Quite strange. But I got the problem.  
The first version `a .+= (true) ? [1,1,1] : 0` works. But `a .+ (true) ? [1,1,1] : 0` or `c = a .+ (true) ? [1,1,1] : 0` won’t work. I typed the problematic one.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 2, 2023, 2:34pm UTC](https://discourse.julialang.org/t/question-mark-with-dot-operations/99758/6 "2023-06-02T14:34:21Z")

</div>

In `a .+ (true) ? [1,1,1] : 0` you are trying first to sum a boolean number with a number to get a boolean value, from there you have an error.  
It is just an issue about precedences, this work as expected: `a .+ ((true) ? [1,1,1] : 0)`

---

<div class="post-metadata">

**Author:** ![Betristor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/betristor/32/45264_2.png) [@Betristor](https://discourse.julialang.org/u/Betristor)\
**Post date:** [June 2, 2023, 3:00pm UTC](https://discourse.julialang.org/t/question-mark-with-dot-operations/99758/7 "2023-06-02T15:00:51Z")

</div>

Thanks, this makes sense. I thought the question mark should organize `(true) ? [1,1,1] : 0` as a whole part but it proved me wrong.
