ELENA-LANG / elena-lang

ELENA is a general-purpose language with late binding. It is multi-paradigm, combining features of functional and object-oriented programming. Rich set of tools are provided to deal with message dispatching : multi-methods, message qualifying, generic message handlers, run-time interfaces
https://elena-lang.github.io/
MIT License
227 stars 23 forks source link

Calling own method directly without target #646

Closed arakov closed 2 months ago

arakov commented 2 months ago

Is your feature request related to a problem? Please describe. In many cases providing self target serves no purpose. And it is not intuitive for the beginners

Describe the solution you'd like If there are no functions with the same name accessible in the code, the compiler will try to check if there are a method declared in the scope class with similar number of parameters. If the method is found the target will be added automatically - self

It must have preceding over a function.

So the implicit code:

singleton TestHelper
{
   myMethod() {}

   myMethodInvoker()
   {
      myMethod()
   }
}

will be equivalent to the explicit one:

singleton TestHelper
{
   myMethod() {}

   myMethodInvoker()
   {
      self.myMethod()
   }
}

Note that for calling a weak self (in case of target overriding), the target must be provided as before:

singleton TestHelper
{
   myMethodInvoker()
   {
      weak self.myMethod()
   }
}
arakov commented 2 months ago

Done in ELENA 6.0.10