I am working on a new class based, dynamically typed programming language where functions are first class objects. Functions defined inside a class (aka methods) are called passing self as first parameter while globally defined functions does not need to have the self parameter.
In a code like:
func foo(a) {
return a*2;
}
class c3 {
var p1 = 555;
func init() {
p1 = foo;
}
}
class c2 {
var p1 = 333;
func init() {
p1 = c3();
}
}
class c1 {
var p1 = 111;
func init() {
p1 = c2();
}
}
func main() {
return c1().p1.p1.p1(1234);
}
How can the compiler decide if self needs to be passed as first argument to p1(1234) or not? In this case p1 points to foo which is a global function that would not need the self parameter.