> In Julia, all arguments to functions are passed by reference.
Is this really true? I know it's written in the multi-dimensional arrays
section of the manual but it's a pretty broad statement. I was trying to
debug some code, the issue turns out to have nothing to do with how values
are passed to functions, but I got a bit frustrated by the following
behaviour.
This one works
type TType
val :: Int;
end
function boo(tt :: TType)
tt.val = 7
end
t = TType(20)
t.val
boo(t)
t.val
This one doesn't
function hoo(d :: Int)
d += 1;
end
a = 2
hoo(a)
a
Now let's go crazy:
function goo(s)
s += 1;
end
function zoo(w)
w[1] += 1;
w[2] -= 1;
end
d = [1 2]
goo(d)
d
zoo(d)
d
Part of me 'gets it'. But on another level I find this a little
inconsistent (I have similar issues with some of the variable scoping
rules). I'm not necessarily opposed to the choices which have been made but
I find that they're not really expanded upon in the manual in sufficient
detail.
Have I missed something? (I'm looking for pointers to make my life easier,
I'm not here to whinge about the frankly sterling work the developers are
doing).
Thanks,
David.