I am also new to Julia and I had the same request a few times ago.
Now I would solve your problem with the following code, thanks for help from
Understanding Object Oriented Programming in Julia - Objects-part 1 ,
I know that the anonymous fix is ββnot very fast, but I think the overhead is not so bad for the print function.
#!/usr/bin/env julia type Person name::AbstractString male::Bool age::Float64 children::Int describe::Function function Person(name,male,age,children) this = new() this.name = name this.male = male this.age = age this.children = children # anonymous functions are not known to be fast ;-) this.describe = function() describe(this) end this end end function describe(p::Person) println("Name: ", p.name, " Male: ", p.male) println("Age: ", p.age, " Children: ", p.children) end ted = Person("Ted",1,55,0) # describe(ted) ted.describe()
However, as 0xMB said: this is not Julia's way. But I like the method of calling chains of calls from Ruby, so I hope that the parser comes up one day to be able to easily create some alias to create such a "member function".
- Maurice
mdiam source share