julia> v1 = Any[2, 3, 5, 7, 11, 13, 17]
7-element Vector{Any}:
2
3
5
7
11
13
17
julia> v1[1:3] .= Ref([4,5,6])
3-element view(::Vector{Any}, 1:3) with eltype Any:
[4, 5, 6]
[4, 5, 6]
[4, 5, 6]
julia> v1
7-element Vector{Any}:
[4, 5, 6]
[4, 5, 6]
[4, 5, 6]
7
11
13
17
julia> v1[1:3] .= "1"
3-element view(::Vector{Any}, 1:3) with eltype Any:
"1"
"1"
"1"
julia> v1
7-element Vector{Any}:
"1"
"1"
"1"
7
11
13
17
Taking your questions one at a time:
v[1:3] .= [4,5,6]
broadcasts over left and right hand side objects, unless told otherwise.- If you want to not broadcast over the RHS, tell Julia not to do so by enclosing the vector in
Ref
. - But then you need to set up the vector
v1
so it can hold objects other thanInt
. Hence theAny
inv1 = Any[2,3,5,7,11,13,17]
. This is also why your string assignment fails (not because of broadcasting.