What does the name of a function denote?

We are going deep into the woods here, but I’ll explain how I see what happens in reality for the JVM:

if you call inc(3) you are directly invoking the function using invokeVirtual. A function value (for storing or passing as parameter) is actually implemented as a class or object (depending on captures) that has an invoke method that is implemented to call the referenced function. This object/class is reference site specific (there could be multiple equal classes as a result – this is a compiler implementation limitation).

If you were to call (::inc)(3) this could be optimized at compiler level (JVM is another matter), but likely is not. Even conceptually, for a free function the name is not a factory as there only needs to be 1 instance. For a method the object reference must be captured which conceptually leads to a functor (function object) factory that takes the object as reference and then calls the body. (Ignoring the chicken-egg issues with this view).

1 Like