# Julia broadcasting notation: period before or after?

**URL:** https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629
**Category:** New to Julia
**Created:** [June 9, 2021, 2:48pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629 "2021-06-09T14:48:07Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://discourse.julialang.org/u/Thomas)
#### Post date: [June 9, 2021, 2:48pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/1 "2021-06-09T14:48:08Z")

</div>

Why broadcasting for operators like +,\*,^ have a period before and for function like sin have a period after? Silly examples are

> [1,2,3] +. 4  
> +.([1,2,3],4)  
> [1,2,3]==.[4,5,6]

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [June 9, 2021, 2:58pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/2 "2021-06-09T14:58:59Z")

</div>

In-fix function have the dot before, normal ones after. If you want to apply an infix “normally” you have to use parenthesis:

```julia
julia> (+).([1,2,3],4)
3-element Vector{Int64}:
 5
 6
 7

```

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [June 9, 2021, 3:05pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/3 "2021-06-09T15:05:23Z")

</div>

I am not sure if this is the only reason, but there is an ambiguity problem that arises from the fact Julia allows floating point literals to start at the dot.

```julia
1.0+.5 # ambiguous parsing if the dot was after the operator

```

Not sure if there is some reason for not putting the dot always at the start (as function names cannot begin with numbers).

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [June 9, 2021, 3:06pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/4 "2021-06-09T15:06:08Z")

</div>

The answer here is history and a gradient descent to a local optimum. You can kinda-sorta ret-con it into making sense by thinking of the `(` as a function application operator.

---

<div class="post-metadata">

### Author: ![Fliks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fliks/32/2494_2.png) [@Fliks](https://discourse.julialang.org/u/Fliks)
#### Post date: [June 9, 2021, 3:09pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/5 "2021-06-09T15:09:11Z")

</div>

But you get the same ambiguity with the dot in front of the plus because you don’t need to write the zero in 1.0

```julia
1.+0.5

```

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [June 9, 2021, 3:11pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/6 "2021-06-09T15:11:59Z")

</div>

I would have opted for the maximum ambiguity example myself…

```julia
1.+.5

```

---

<div class="post-metadata">

### Author: ![AndreLC](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@AndreLC](https://discourse.julialang.org/u/AndreLC)
#### Post date: [June 9, 2021, 3:14pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/7 "2021-06-09T15:14:08Z")

</div>

Also, functions names will be preceded by a dot if the module is not implicit, eg. `Bar.foo()`

---

<div class="post-metadata">

### Author: ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://discourse.julialang.org/u/Thomas)
#### Post date: [June 9, 2021, 3:14pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/8 "2021-06-09T15:14:15Z")

</div>

What does this syntax (…) do? I think it depends on the context:

> (1,2) # construct tuple  
> (+) # generic function

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [June 9, 2021, 3:16pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/9 "2021-06-09T15:16:41Z")

</div>

Yeah, that’s the kinda-sorta part. Parens are also used for precedence, grouping of expressions, tuples, named tuples and more… in addition to function calls.

In actuality, you can’t split `sin.(x)`, into either `sin.` nor `.(`. It’s just `sin.(x)`. That’s just the way it is.

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [June 9, 2021, 3:19pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/10 "2021-06-09T15:19:09Z")

</div>

Broadcasting doesn’t work without it. It is for operators like `+` that aren’t “normally” used as functions, even though they do have corresponding functions. So while you can use the `+(x,y)` function for scalars, it does not work if you want to broadcast it unless you are a bit more explicit about what you are broadcasting which is what the parentheses give you.

```julia
julia> 1 .+ [2,3]
2-element Vector{Int64}:
 3
 4

julia> +.(1,[2,3])
ERROR: syntax: numeric constant "." cannot be implicitly multiplied because it ends with "."
Stacktrace:
 [1] top-level scope
   @ none:1

julia> (+).(1,[2,3])
2-element Vector{Int64}:
 3
 4

```

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [June 9, 2021, 5:10pm UTC](https://discourse.julialang.org/t/julia-broadcasting-notation-period-before-or-after/62629/11 "2021-06-09T17:10:42Z")

</div>

This important part is the comma. `(1,)` makes a tuple, but `(1)` is just `1` where the parentheses define precedence.
