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