# Dot syntax in .7

**URL:** <https://discourse.julialang.org/t/dot-syntax-in-7/10217>\
**Category:** New to Julia\
**Created:** [April 7, 2018, 9:32am UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217 "2018-04-07T09:32:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [April 7, 2018, 9:32am UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/1 "2018-04-07T09:32:32Z")

</div>

I was looking at the most recent version of .7 and noticed a lot of the dot syntax was not working. Is this feature broken or being deprecated?

Here are some examples:

```julia
function f(x)
    if rand() < .5
        return x + 1
    else 
        return x - 1
    end 
end

f.(rand(10))
ERROR: MethodError: no method matching getproperty(::typeof(f), ::Tuple{Array{Float64,1}})
Closest candidates are:
  getproperty(::Any, ::Symbol) at sysimg.jl:18

```

```julia
x = [rand(2) for i in 1:10]
x .+ [1 2]
┌ Warning: `a::AbstractArray + b::Number` is deprecated, use `broadcast(+, a, b)` instead.
│ caller = macro expansion at broadcast.jl:341 [inlined]
└ @ Core broadcast.jl:341

```

```julia
a = rand(3,3)
a .= .1
┌ Warning: Deprecated syntax `using the value of `.=``.
└ @ nothing none:0

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 7, 2018, 9:47am UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/2 "2018-04-07T09:47:47Z")

</div>

The first example looks like a bug (something with global scope?):

```julia
julia> x = rand(2);

julia> f(x) = sin.(x);

julia> f(x)
2-element Array{Float64,1}:
 0.3560585848659661
 0.7432072794002402

julia> sin.(x)
ERROR: MethodError: no method matching getproperty(::typeof(sin), ::Tuple{Array{Float64,1}})
Closest candidates are:
  getproperty(::Any, ::Symbol) at sysimg.jl:18

```

The third example is

[https://github.com/JuliaLang/julia/issues/26516](https://github.com/JuliaLang/julia/issues/26516)

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [April 7, 2018, 10:08am UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/3 "2018-04-07T10:08:49Z")

</div>

Thanks for the info. I can’t say I understand all of the design implications, but I’m hoping most of the dot syntax is preserved. I think its among Julia’s best features.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [April 7, 2018, 12:21pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/4 "2018-04-07T12:21:33Z")

</div>

What version of v0.7 are you using?  
This is the version I’m using:

```julia
julia> versioninfo()
Julia Version 0.7.0-DEV.4806
Commit 98b1206 (2018-04-06 19:49 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin17.5.0)
  CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
Environment:

```

I thought that some of that might be fixed already.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [April 7, 2018, 12:24pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/5 "2018-04-07T12:24:52Z")

</div>

Confirmed on latest master. Filed as [https://github.com/JuliaLang/julia/issues/26739](https://github.com/JuliaLang/julia/issues/26739).

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [April 7, 2018, 1:22pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/6 "2018-04-07T13:22:58Z")

</div>

It looks like example 1 is a bug and 3 is in flux. Does anyone know the status behind the second example?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 7, 2018, 1:27pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/7 "2018-04-07T13:27:11Z")

</div>

That should be the same as

```julia
julia> [1 2] + 3
┌ Warning: `a::AbstractArray + b::Number` is deprecated, use `broadcast(+, a, b)` instead.
│ caller = top-level scope
└ @ Core :0
1×2 Array{Int64,2}:
 4 5

```

which is a valid warning — the `+` is applied elementwise in your example, with the elements being vectors and numbers.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [April 7, 2018, 1:30pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/8 "2018-04-07T13:30:29Z")

</div>

Interesting. It works in .6.2 for some reason. It adds 1 to the first element of each sub-array and 2 to the second element of each sub-array. Is there a way to achieve that in .7?

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [April 7, 2018, 1:32pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/9 "2018-04-07T13:32:15Z")

</div>

> [@Christopher\_Fisher](#):
>
> x = [rand(2) for i in 1:10]  
> x .+ [1 2]

Correction: it creates a 10×2 Array{Array{Float64,1},2}. It works in .6.2 nonetheless.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 7, 2018, 1:37pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/10 "2018-04-07T13:37:39Z")

</div>

> [@Christopher\_Fisher](#):
>
> It works in .6.2 for some reason.

The reason is that they were deprecated for `v0.7`. See

> <https://github.com/JuliaLang/julia/pull/22932>
>
> There has been much discussion around this lately. This PR deprecates \`array + s…calar\` (and related) in favor of \`array .+ scalar\` for v0.7 (with the possibility of introducing behavior such that \`matrix + scalar == matrix + scalar\*I\` in v1.0 in a separate PR).
> 
> The arguments for changing the behavior of \`array + scalar\` from elementwise are:
> 
> \* Apart from the binary \`Number\`/\`AbstractArray\` methods deprecated in this PR, all the other methods of \`+\`, \`-\`, \`\*\`, \`/\` involving \`AbstractArray\` are motivated by and consistent with linear algebra. For instance \`vector + vector\` is defined because \`vector\` belongs to a vector space (not because \`vector .+ vector\` is inconvenient) and a such, the entire container adds (not just the elements). However, the current element-wise definition seems to be incorrect for linear algebra. For instance, if I write a polynomial function such as \`f(a,b,c,x) = a\*x^2 + b\*x + c\`, I expect it to work for any \`x\` that belongs to a field/ring/whatever. However, this definition is broken if \`x\` is a square matrix - you expect behavior like \`f(a,b,c,x) = a\*x^2 + b\*x + c\*I\` but currently the \`c\` is added to all parts of the matrix, not just the diagonal part. It is therefore difficult to write generic code that works for a wide range of types of \`x\` (though I would note \`a\*x\*x + b\*x + c\*one(x)\` currently works for \`x::Number\` and \`x::AbstractMatrix\`, though the extra \`one\` seems unnatural).
> \* It seems to violate a property of \`one\` that you might expect, whereby \`array + scalar != array + scalar\*one(array)\`
> \* AFAIK these are the last auto-vectorized methods that haven't been deprecated as a part of the dot-call changes (e.g. \`sin(array)\` no longer works; rather \`sin.(array)\` is necessary). In this situation, I would actually argue that \`array .+ scalar\` for elementwise addition is less confusing... it's less of a special case.
> 
> The primary arguments against (that I am aware of) are:
> 
> \* The current \`array + scalar\` behavior is convenient (though \`.+\` is hardly much harder to type that \`+\`).
> \* We tried this once before and it was difficult (before the dot-call convention was introduced and well-known?)

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [April 7, 2018, 1:38pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/11 "2018-04-07T13:38:43Z")

</div>

Excellent. Thank you.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [April 7, 2018, 3:23pm UTC](https://discourse.julialang.org/t/dot-syntax-in-7/10217/12 "2018-04-07T15:23:59Z")

</div>

> [@Christopher\_Fisher](#):
>
> Interesting. It works in .6.2 for some reason. It ~~adds~~ [might be thought to add] 1 to the first element of each sub-array and 2 to the second element of each sub-array. Is there a way to achieve that in .7?

```julia
x .+ [[1;2]]

```
