>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
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
wrote:
> From the manual
> Argument Pa
I also tried to write an additional explanation for this recently in case the
manual isn't sufficient:
http://www.johnmyleswhite.com/notebook/2014/09/06/values-vs-bindings-the-map-is-not-the-territory/
-- John
On Sep 26, 2014, at 2:01 PM, Stefan Karpinski wrote:
> x is a variable, not a valu
Matlab’s semantics are called copy-on-write. I suspect you couldn’t implement
those semantics without several months of work on a new Array type.
— John
On Sep 27, 2014, at 1:52 PM, Stephan Buchert wrote:
> Thanks for the kind explanations and references that I had missed, seems
> clear to m
If you're willing to tolerate some performance hit, a simple wrapper
type COWArray{T,N}
A::Array{T,N}
copied::Bool
end
and then defining variants of setindex! that look like
function setindex!(A::COWArray, v, indexes...)
if !A.copied
A.A = copy(A.A)
A.copied = true