Is funcName(...) syntactic sugar for (::funcName).invoke(...)?

So it’s very much like methods and method references in Java, but these are platform specific details.

I would say that, conceptually, funcName is a name of a function factory, very much like ClassName is a name of a class type. The name as such is a compile time thing. If funcName is used syntactically in a call context such as funcName(...), the runtime experiences no trace of an entity representing that function (and no hook to that entity) nor a trace to a method such as invoke being involved (and no hook to such a method). The runtime experiences just the result of a function call. That means the compiler is entitled to optimze a function call in whatever way as long as there is nothing observable or accessible to the runtime.

On the other hand, ::funcName sets the function name in another syntactic context and refers to an instance of a KFunction, an instance that is accessible to the runtime for reflection purposes and being callable as defined by the supertype KCallable of KFunction and being invokeable as defined by the supertype Function of KFunction.

That means: The function name of a function declaration used in a call context refers to the concept of a function call, which is not meant to be an instance of whatever type. Used in the context of a callable reference, the function name refers to an instance of Function among others, namely KFunction and KCallable.

1 Like