Suppose I have defined a function:
def hello(name:String, words:String) = println("Hello!" + name + words)
Then I defined a partial function:
def p = hello _
Print p, displayed:
(String, String) => Unit = <function2>
There’s no function name displayed. Is it possible to get the original method name hello from the partial function p?
There has been some discussion on the mailing lists recently about a language construct that allows you to identify the current method that you’re in. It would be called something like
thisMethodand would essentially do for methods whatthisdoes for class instances.I’d be interested to see how this interacts with functions (which are a different concept from methods). Your
pis an anonymous function created from partially applying thehellomethod (again, you need to be careful here, a “partially applied function is a very different thing from aPartialFunction). The actual method then invoked would beapplyon this function object, and there are several possibilities as to howthisMethodcould behave in such a case.Whatever happens,
pis just an object reference, don’t expect to ever be able to access it as a name.