# Why is multiplication A\*B\*C left-associative (\`foldl\`) not right-associative (\`foldr\`)?

**URL:** <https://discourse.julialang.org/t/why-is-multiplication-a-b-c-left-associative-foldl-not-right-associative-foldr/17552>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 15, 2018, 8:52am UTC](https://discourse.julialang.org/t/why-is-multiplication-a-b-c-left-associative-foldl-not-right-associative-foldr/17552 "2018-11-15T08:52:07Z")\
**Posts on this page:** 1\
**Showing post:** 27

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [November 17, 2018, 9:09am UTC](https://discourse.julialang.org/t/why-is-multiplication-a-b-c-left-associative-foldl-not-right-associative-foldr/17552/27 "2018-11-17T09:09:02Z")

</div>

BTW, `*` in Julia’s AST do not say it’s left- or right-associative:

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

```

(I found that it’s strange. Why is that?)

So it’s easy to get right-associative `*` a la future-import (provided you do it before any use of `*`):

```julia
julia> module RightAssociative
       *(a) = Base.:*(a)
       *(a, b) = Base.:*(a, b)
       *(args...) = *(args[1:end-2]..., *(args[end-1], args[end]))
       end
Main.RightAssociative

julia> using .RightAssociative: *

julia> Base.:*(x::Symbol, y) = Symbol("($x * $y)")

julia> :a * :b * :c
Symbol("(a * (b * c))")

```

where the result of the last output would be `Symbol("((a * b) * c)")` without `using .RightAssociative: *`.

---

_[View the full topic](https://discourse.julialang.org/t/why-is-multiplication-a-b-c-left-associative-foldl-not-right-associative-foldr/17552)._
