> Also one weird thing that I came across lately, which is not obvious in the 
> light of the previous is that if you take your first function and pass to 
> it a row or column of a matrix, the original matrix won't be modified. Try 
> for example ftest(eye(2)[:,2]).

At the moment, slicing an array will make a copy and not a view (like
e.g.  Numpy does).  However, I think this will change in the future.

> Hope this reply helped.
>
> On Sunday, 29 June 2014 11:24:42 UTC+2, Stéphane Laurent wrote:
>>
>> Hello, 
>>
>>  As a R user I am a little puzzled by this behaviour:
>>
>> *julia> ftest = function(x) *
>> *        x[2] = 0 *
>> *        return x*
>> *       end*
>> *(anonymous function)*
>>
>> *julia> y = [1,2]*
>> *2-element Array{Int64,1}:*
>> * 1*
>> * 2*
>>
>> *julia> ftest(y)*
>> *2-element Array{Int64,1}:*
>> * 1*
>> * 0*
>>
>> *julia> y*
>> *2-element Array{Int64,1}:*
>> * 1*
>> * 0*
>>
>>
>> In R, this function doesn't modify the variable passed in the argument:
>>
>> *> f <- function(x){ x[2] <- 0; return(x)}*
>> *> y=1:2*
>> *> f(y)*
>> *[1] 1 0*
>> *> y*
>> *[1] 1 2*
>>
>> Please could you tell me whether this is a good solution :
>>
>> *ftest = function(x) *
>> * x = deepcopy(x)*
>> * x[2] = 0 *
>> * return x*
>> *end*
>>

-- 

Reply via email to