<p dir="auto">I'm in the middle of a migration from C++ and I'm having a hard time in understanding Julia "slices".</p>
<p dir="auto">I have a vector <code class="notranslate">a</code>. When I do <code class="notranslate">b=a[1:2]</code> and <code class="notranslate">b[1] = 10</code> for example, <code class="notranslate">a</code> is not affected.<br>
That is, the "slicing" operation <code class="notranslate">a[1:2]</code> creates a copy instead of working with the original data.</p>
<p dir="auto">Is this a bug or intended behavior?</p>
<p dir="auto">If it is intended behavior, what is the correct way of getting a reference to a piece of the original vector? (whose type is still Vector, not SubArray; I have functions with explicit type annotations for type safety).</p>
<p dir="auto">I would prefer that range indexing of an <code class="notranslate">Array</code> (e.g. <code class="notranslate">X[1:10, :]</code>) created a <code class="notranslate">SubArray</code> (a view/reference), not a copy.   This seems more in the spirit of Julia's pass-by-reference semantics, and would eliminate some of the performance gotchas with range indexing.</p>
<p dir="auto">It might also make future loop-devectorization optimization easier, because subarray references can be devectorized back into references to the original array without worrying that you will be changing the semantics.</p>
<p dir="auto">It would reduce Matlab compatibility, but we already do that with pass-by-reference and so I doubt many users will be surprised by having the same reference semantics for range indexing.</p>
<p dir="auto">This is something that has come up informally several times on the mailing list, but I didn't see any issue for it.</p>