Reference to two vectors?

suppose I have two vectors:

a = [1, 2];
b = [3, 4]

how could I create a single “reference” vector c, which is a concatenation of a and b, so that any changes in each would be reflected in the others??

for example, below is a failed attempt:

julia> c = [view(a, :); view(b, :)]
4-element Array{Int64,1}:
 1
 2
 3
 4

julia> a[1] = 10
10

julia> c
4-element Array{Int64,1}:
 1
 2
 3
 4

here c is a concrete vector rather than a reference, hence any changes in a is not able to see in c.

please help

Not sure how to do what you asked for, but can you go the other way?

c = [1,2,3,4]
a = view(c, 1:2)
b = view(c, 3:4)
a[1] = 10
b[1] = 11
julia> c
4-element Array{Int64,1}:
 10
  2
 11
  4
5 Likes

OH!!! I’m just too stupid and rigid to overlook this solution :crazy_face: thanks.

That’s a good solution. There’s also https://github.com/ahwillia/CatViews.jl

4 Likes