Hi Julia-users,
I'd find it natural to attach a method to a particular instance of an
object as in traditional object-oriented programming (see the example
below). I can manage this with the constructor NewFoo, which binds the
instance to the method after the object is created. Is this idiomatic in
Julia? Is there a more idiomatic way? The most I could find in Julia
documentation on the subject was this footnote:
http://docs.julialang.org/en/release-0.2/manual/methods/#id1
Thanks in advance,
Sean
type Foo
x::Number
y::Number
Compute::Function
end
function NewFoo(x, y)
f = Foo(x, y, function() 0 end)
f.Compute = function() f.x + f.y end
f
end
foo = NewFoo(2, 3)
foo.Compute()