Golang-like member functions

peteole
Sun, 25 Jul 2021 07:40:04 +0000
Internals & Design

Hi, I recently found out about the notation for callables:

function (obj::MyType)(x::Int)
    return obj.mymember*x
end

I realized this syntax is extremely similar to the golang and rust-notation for member functions. So we don’t we just make the following possible:

function (obj::MyType) myMemberFunction(x::Int)
   return obj.mymember*x
end
myObject::MyType=getObjFromSomewhere()
y=myObject.myMemberFunction(6) # y==myObject.myMenber*6

I think this would fit extremely well in the language design and enable much more advances packages since it would be possible to add some OOP-patterns which may make sense at some point.
What do you think about it?

13 posts - 7 participants