# Is \* a ternary/quarternary operator in 1.7+, or am I missing something that was there before?

**URL:** <https://discourse.julialang.org/t/is-a-ternary-quarternary-operator-in-1-7-or-am-i-missing-something-that-was-there-before/83714>\
**Category:** Internals & Design\
**Created:** [July 3, 2022, 10:35pm UTC](https://discourse.julialang.org/t/is-a-ternary-quarternary-operator-in-1-7-or-am-i-missing-something-that-was-there-before/83714 "2022-07-03T22:35:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 3, 2022, 10:35pm UTC](https://discourse.julialang.org/t/is-a-ternary-quarternary-operator-in-1-7-or-am-i-missing-something-that-was-there-before/83714/1 "2022-07-03T22:35:26Z")

</div>

So I noticed this bit in matmul.jl

```julia
# Three-argument *
"""
    *(A, B::AbstractMatrix, C)
    A * B * C * D
Chained multiplication of 3 or 4 matrices is done in the most efficient sequence,
based on the sizes of the arrays. That is, the number of scalar multiplications needed
for `(A * B) * C` (with 3 dense matrices) is compared to that for `A * (B * C)`
to choose which of these to execute.

```

Which implies that a chain of \* is not parsed as a sequence of binary operations. I was not aware of this, and looks like it works for any length chain.

```julia
julia> module MyMul
         *(x,y,z) = 3
         *(x,y,z,a,b,c) = 6
         function test()
           println(1*2*3)
           println(1*2*3*4*5*6)
           println(1*2*3*4)
         end
       end
Main.MyMul

julia> MyMul.test()
3
6
ERROR: MethodError: no method matching *(::Int64, ::Int64, ::Int64, ::Int64)
You may have intended to import Base.:*

```

Is this a v1.7 parser change, or is this something else? What other operators can I expect to act like this?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 3, 2022, 10:42pm UTC](https://discourse.julialang.org/t/is-a-ternary-quarternary-operator-in-1-7-or-am-i-missing-something-that-was-there-before/83714/2 "2022-07-03T22:42:27Z")

</div>

> [@Benny](#):
>
> `You may have intended to import Base.:*`

```julia
julia> module MyMul
         import Base.:*
         *(x,y,z) = 3
         *(x,y,z,a,b,c) = 6
         function test()
           println(1*2*3)
           println(1*2*3*4*5*6)
           println(1*2*3*4)
         end
       end
Main.MyMul

julia> MyMul.test()
3
6
24

```

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [July 3, 2022, 11:27pm UTC](https://discourse.julialang.org/t/is-a-ternary-quarternary-operator-in-1-7-or-am-i-missing-something-that-was-there-before/83714/3 "2022-07-03T23:27:53Z")

</div>

> [@Benny](#):
>
> Is this a v1.7 parser change, or is this something else? What other operators can I expect to act like this?

I believe the only other such operators are `+` and `++`. And that the parsing has worked this way forever, certainly on 1.0:

```julia
julia> :(1*2*3) |> dump
Expr
  head: Symbol call
  args: Array{Any}((4,))
    1: Symbol *
    2: Int64 1
    3: Int64 2
    4: Int64 3

julia> :(1+2+3)
:(1 + 2 + 3)

julia> :(1++2++3)
:(1 ++ 2 ++ 3)

julia> :(1/2/3)
:((1 / 2) / 3)

julia> VERSION
v"1.0.5"

```

For `+` and `*`, there are fallback definitions which work left-to-right, e.g. `@less 1 * 2 * 3`. What is new on 1.7 is that some chains of matrix multiplication will be done in other orders if this is more efficient. (Before this, there were also some other specialisations such as `@which [1,2]' * Diagonal([3,4]) * [5,6]`.)

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [July 4, 2022, 12:17am UTC](https://discourse.julialang.org/t/is-a-ternary-quarternary-operator-in-1-7-or-am-i-missing-something-that-was-there-before/83714/4 "2022-07-04T00:17:13Z")

</div>

> [@Benny](#):
>
> ```julia
> 
> ```
> 
> Which implies that a chain of \* is not parsed as a sequence of binary operations. I was not aware of this, and looks like it works for any length chain.

Exactly that, for the operator `+` and `*` this is stated in the documentation [here](https://docs.julialang.org/en/v1/devdocs/ast/#Operators). But it also works like that for `++` too.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 4, 2022, 2:10am UTC](https://discourse.julialang.org/t/is-a-ternary-quarternary-operator-in-1-7-or-am-i-missing-something-that-was-there-before/83714/5 "2022-07-04T02:10:34Z")

</div>

I intentionally avoided modifying `Base.:*`, I didn’t want anyone to run that example and have to restart their session afterward.
