Given:
julia> a = zeros(5); b = zeros(5); R = collect(10:10:100);
This naturally fails:
julia> a[1:end] = R
ERROR: DimensionMismatch("tried to assign 10 elements to 5 destinations")
Stacktrace:
[1] throw_setindex_mismatch(::Array{Float64,1}, ::Tuple{Int64}) at .\indices.jl:92
[2] setindex_shape_check(::Array{Float64,1}, ::Int64) at .\indices.jl:143
[3] setindex!(::Array{Float64,1}, ::Array{Float64,1}, ::UnitRange{Int64}) at .\array.jl:618
But then this succeeds:
julia> c, d = R;
julia> c
10
julia> d
20
Why doesn’t this fail with a “tried to assign 10 elements to 2 destinations” error? Why does Julia silently discard the rest of the values in such cases?
Also:
julia> a[1:end],b = R;
julia> (a,)
([10.0, 10.0, 10.0, 10.0, 10.0],)
julia> (b,)
(20,)
This is seen as a broadcast of R’s first value into a
(and gives an appropriate warning in 0.7), whereas:
julia> m, n, o, p, q, b = R;
julia> (m, n, o, p, q)
(10, 20, 30, 40, 50)
julia> (b,)
(60,)
distributes R’s values over the variables.
What will be the semantics of the previous a[1:end],b = R;
assignment after the deprecation is removed?
And is there an easy way to get the effect of a[1], a[2], a[3], a[4], a[5], b = R;
with more compact and more generalizable code?