# Dot syntax

**URL:** <https://discourse.julialang.org/t/dot-syntax/96789>\
**Category:** General Usage\
**Created:** [March 29, 2023, 4:38pm UTC](https://discourse.julialang.org/t/dot-syntax/96789 "2023-03-29T16:38:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lancejnelson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lancejnelson/32/21898_2.png) [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)\
**Post date:** [March 29, 2023, 4:38pm UTC](https://discourse.julialang.org/t/dot-syntax/96789/1 "2023-03-29T16:38:45Z")

</div>

I can’t see why these three statements do different things:

```julia
data = [4;3;2;1;5]

x = data .- findmin(data)[1] # Subtract the min from each value. Does what I want.
x = @. data - findmin(data)[1] # Error, can't broadcast because it "sees" an array of length 2???
x = @. data - getindex(findmin(data),1). # Works but doesn't produce the desired result.

```

I feel like all three lines should do the same thing: subtract the minimum value from each number in the array?

---

<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:** [March 29, 2023, 4:44pm UTC](https://discourse.julialang.org/t/dot-syntax/96789/2 "2023-03-29T16:44:44Z")

</div>

`@.` makes _all_ functions broadcasted. In other words, `@. data - findmin(data)[1]` becomes:

```julia
data .- findmin.(data)[1]

```

You don’t want to broadcast `findmin` and apply it separately to each element. If you write the indexing as a function call, it’ll _also_ broadcast `getindex` over that result.

---

<div class="post-metadata">

**Author:** ![lancejnelson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lancejnelson/32/21898_2.png) [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)\
**Post date:** [March 29, 2023, 4:48pm UTC](https://discourse.julialang.org/t/dot-syntax/96789/3 "2023-03-29T16:48:19Z")

</div>

Thanks. So this particular example isn’t a good candidate for `@.`

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 29, 2023, 9:02pm UTC](https://discourse.julialang.org/t/dot-syntax/96789/4 "2023-03-29T21:02:35Z")

</div>

> [@lancejnelson](#):
>
> `findmin(data)[1] `

Don’t you mean `minimum(data)`?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 30, 2023, 1:10am UTC](https://discourse.julialang.org/t/dot-syntax/96789/5 "2023-03-30T01:10:44Z")

</div>

> [@lancejnelson](#):
>
> Thanks. So this particular example isn’t a good candidate for `@.`

You can opt-out of the dotting for particular function calls with `$`, e.g.

```julia
x = @. data - $findmin(data)[1]

```

(This is explained in the `@.` documentation.)

---

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [May 4, 2023, 5:50pm UTC](https://discourse.julialang.org/t/dot-syntax/96789/6 "2023-05-04T17:50:24Z")

</div>

Related, when using `@.`, is there a way to opt out of the dotting within parentheses?

For example, for scalars `α`, `β`, and a vector `x`, I would like to perform `(α * β) .* x`. using `@.` I thought I would prevent the penetration of the dot into the parenthesized expression by `@. $(α * β) * x`, but it seems that both `@. (α * β) * x` and `@. $(α * β) * x` generate the same native code according to `@code_native`, so I’m confused.

---

<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:** [May 4, 2023, 5:53pm UTC](https://discourse.julialang.org/t/dot-syntax/96789/7 "2023-05-04T17:53:33Z")

</div>

That works. Code native isn’t really where you should be checking this sort of thing — you’re almost surely not looking at what you think you’re looking at.

```julia-repl
julia> Meta.@macroexpand @. (α * β) * x
:((*).((*).(α, β), x))

julia> Meta.@macroexpand @. $(α * β) * x
:((*).(α * β, x))

```
