Why I love python.
Tue Aug 17 03:44:43 CEST 2004
Nick Patavalis <npat at efault.net> writes:
> If you define a function like:
> def sum (a, b):
> return a + b
> How can the compiler know what code to produce? It could trace all the
> applications of sum(), and decide what types of arguments sum() is
> actually applied on. But this is not easy, and sometimes it is
> straight-out impossible.
Compilers for languages like Lisp and Smaltalk have dealt with this
for decades. They can either generate code that switches on the type
tags, or have dispatch tables in the objects that point to code for
operations like "+", or take advice or declarations from the
programmer about the arg types, among other possibilities. Any of
these approaches generates code that runs much faster than interpreted code.
More information about the Python-list