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
Previous text:
2003-09-17 04:24: Subject: Re: float type weirdness
On Tue, Sep 16, 2003 at 08:35:02PM -0400, Martin Stjernholm, Roxen IS @ Pike developers forum wrote:
there's no difference between single and double quotes and then whines about the "mystical" behavior when the single quoted "strings" are used in place of real strings.
Not really. Usually compiler signals an error when quotes are misused (at least Pike/C will - double quotes are strings, while singe quotes are ints).
Just out of curiosity, do you think that testing on run time types (i.e. use of intp, objectp, arrayp etc) is evil in general or is it evil only when used to tell the two numeric types apart?
Well... Frankly, it is useful, sometimes :) And I've no choice when I want to make run-time checks in function/operator which may take arguments of different types.
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.
in those cases. Since Pike isn't strongly typed it's very hard to avoid the runtime type checks that it must do on every operand.
Why? What is the point to have types (compile time) at all? If we know the type of some variable at compile time (and flag this), there is no need to make typechecks during runtime, or?
Regards, /Al
/ Brevbäraren