x is a variable, not a value: http://julia.readthedocs.org/en/latest/manual/faq/#i-passed-an-argument-x-to-a-function-modified-it-inside-that-function-but-on-the-outside-the-variable-x-is-still-unchanged-why
On Fri, Sep 26, 2014 at 4:51 PM, Stephan Buchert <[email protected]> wrote: > From the manual > Argument Passing Behavior: ...means that values are not copied when they > are passed to functions. ...Modifications to mutable values (such as > Arrays) made within a function will be visible to the caller. > > I get > julia> function f(x) > x=x+1 > y=x+1 > end > f (generic function with 1 method) > > julia> x=[1:5]' > 1x5 Array{Int64,2}: > 1 2 3 4 5 > > julia> y=f(x) > 1x5 Array{Int64,2}: > 3 4 5 6 7 > > julia> x > 1x5 Array{Int64,2}: > 1 2 3 4 5 > > Apparently Array x is copied inside the function, at least in this case, > and this is not visible to the caller (here made indirectly visible). The > manual is confusing for me. And what is the difference between my example > and the double! function from the manuals style guide, which does actually > modify the function argument? > >
