If you want to use julia functions like OOP methods just make the first 
argument the object instance so

function setx!(s::State, i::int)
    #modifies s, so we use "!" in function name 
    s.x = i
end

function squarex(s::State)
   return s.x^2
end

#main code
s = State()
setx!(s,2)
#s.x == 2
y =squarex(s)
#y == 4

If you adopt the convention that the "object" is the first argument to the 
function and the later arguments are the parameters of the method, 
s.method(param) translates to function(s, param). So your zero argument 
functions that modify program state become one argument functions that 
modify the state variable that is passed to them. Keep in mind the well 
loved Julia convention that functions which modify their arguments should 
end in "!" like "setx!(s::State)" or "increment!(c::Counter)".

Does this make things easier to reason about? 

James

Reply via email to