Fantom

Login | Register

Call overloading

Xan
30 May 2012

Is this possible to override/define call from a class:

class Foo {
  |Obj -> Obj| function

  ....

}

I want to call Foo like Foo(a) = Foo.function(a).

Is it possible?. I don't see in operator overloading.

Thanks, Xan

KevinKelley
30 May 2012

static member?

class Foo {
  static const |Obj -> Obj| function := |Obj o->Obj| { o }
  static Obj method(Obj o) { o } 
}
class Main {
  static Void main() {
    echo(Foo.function("call a static member func"))
    echo(Foo.method("call a static method"))
  }
}

Note statics must be const; for non-static it's sometimes convenient to use the closure-member form, so you can change it at runtime, but for class members that doesn't apply, so those two variations are pretty much the same thing.

brian
30 May 2012

I want to call Foo like Foo(a) = Foo.function(a).

I'm quite sure what you are asking, but Foo(a) is the constructor syntax which can map to a variety things include an instance or static constructor.

Xan
4 Jun 2012

I'm ask if it's possible to do something like Foo(a) without being a constructor. Being an apply of Foo.function to a. It's just a shortcut. In C++ or C it could be done, or in python:

def __call__(self, *a):
    return self.funcio(*a)

thanks,

brian
4 Jun 2012

No Fantom doesn't allow you to overload (..) operator today - it is handled only by constructors and Funcs.

Xan
4 Jun 2012

Mmm.... a pain. Please, mark it as wishlist in future releases. I think it's pretty for O-O completion.

Regards, Xan.

Login or Register to Reply

Back | All Topics