This is the first time I encountered this issue since I began using Julia 
about a year ago. Thank you for the clarification John. 

On Saturday, July 25, 2015 at 11:48:36 AM UTC-4, John Myles White wrote:
>
>
> http://www.johnmyleswhite.com/notebook/2014/09/06/values-vs-bindings-the-map-is-not-the-territory/
>
> On Saturday, July 25, 2015 at 8:13:33 AM UTC-7, Christopher Fisher wrote:
>>
>> I am writing a program (in .3.1) that takes a one dimensional array of 
>> indices (x) and creates a new one dimensional array of indices  (x = y) and 
>> switches a given pair of elements in the new array. For some reason, the 
>> original array (x) changes when I change the new array (see below). 
>>
>> In [16]:
>>
>> x = [1:5]
>>
>> y = x
>>
>> y[[3;4]] = y[[4;3]]
>>
>> [x y]
>>
>> Out[16]:
>>
>> 5x2 Array{Int64,2}:
>>  1  1
>>  2  2
>>  4  4
>>  3  3
>>
>>
>>
>> However, if I change y = x to y = x[:], the problem does not occur, even 
>> though x and x[:] appear to be the same type.
>>
>>
>> In [15]:
>>
>> x = [1:5]
>>
>> y = x[:]
>>
>> y[[3;4]] = y[[4;3]]
>>
>> [x y]
>>
>> Out[15]:
>>
>> 5x2 Array{Int64,2}:
>>  1  1
>>  2  2
>>  3  4
>>  4  3
>>  5  5
>>
>>
>> The code below shows that this does not seem to be a general property of the 
>> language. As in the previous cases, I define y as x and change y. 
>>
>>
>> In [13]:
>>
>> x = [1:5]
>>
>> y = x
>>
>> y = y*4
>>
>> [x y]
>>
>> Out[13]:
>>
>> 5x2 Array{Int64,2}:
>>  1   4
>>  2   8
>>  3  12
>>  4  16
>>  5  20
>>
>>
>>
>> Certainly, I could use y = x[:] or simply change the original array. 
>> Nonetheless, the inconsistency seems undesirable from my point of view. Is 
>> this a bug? Any help would be appreciated. 
>>
>>
>>

Reply via email to