That's typically called function overloading. Grubba has made some work on adding that to Pike with the variant modifier, but it doesn't work well yet. What it would do in Pike is simply to join the different functions to one that does the necessary runtime type checks to execute the right variant. C++ can do it better since it resolves the right variant already at compile time.
Which is better is of course a matter of what you're trying to achieve. What you describe sounds like multiple dispatch, i.e. a->f(b) will dispatch polymorphically on both a and b, which is something C++ does not have.
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2003-09-17 20:23: Subject: Re: float type weirdness
But something like "function prototypes" (as in C++), where compiler (or runtime) makes the decision which function to call (based on argument types) is more convenient.
That's typically called function overloading. Grubba has made some work on adding that to Pike with the variant modifier, but it doesn't work well yet. What it would do in Pike is simply to join the different functions to one that does the necessary runtime type checks to execute the right variant. C++ can do it better since it resolves the right variant already at compile time.
/.../ What is the point to have types (compile time) at all?
One important benefit is that compile time types help discover many bugs before the program is run. Another is that they make it theoretically possible to remove the runtime type checks in special cases.
If we know the type of some variable at compile time (and flag this), there is no need to make typechecks during runtime, or?
Right. I didn't say it's impossible, only very hard (or perhaps rather a whole lot of work). Flow analysis is necessary to catch cases where the runtime type might not agree with the compile time type, since it's always possible to write code where the compile time typing is thwarted:
void func (int i) { if (!intp (i)) error ("Didn't get an int!\n"); }
int main() { function f = func; f ("fooled you"); }
Furthermore compile time function overloading must be implemented so that it's possible to write a more efficient predef::`+(float,float) that can be chosen instead of the generic predef::`+(mixed...).
And even with all this, runtime checks would still be necessary for ints since they can be either native or bignums.
/ Martin Stjernholm, Roxen IS