Hi all,

I'm a bit confused about how the modification of arguments in Julia works.
I have a (rather huge) code involving this function:

function next_prediction!(f, g, t, x, u, p)
    y = system_observation()
    x = f(t, x, u, p)
    for o in g
        obs = observation()
        o.f(t, x, p, obs)
        y.set(obs)
    end
    return y
end

This function should both return y and modify x. The problem is that it 
modifies x only inside the function, but when I'm out of next_prediction!, 
x is the same as before the function call.
So I created a very short test supposed to mimic the behaviour of 
next_prediction!:

type state
    x
    y
end

s = state(1.0,2.0)

function modify_state!(s)
    s.x = 7.0
    return 3.0
end

println(s)
n = modify_state!(s)
println(s)

and in that case, the function modify_state! both return 3.0 *and* modify 
the state s. How could we explain the fact that in such a basic example, 
everything works as I want, but not in the more complex code?

Thanks a lot!

Reply via email to