What makes functions special?

Terry Reedy tjreedy at udel.edu
Sun Jul 10 09:04:20 CEST 2011


On 7/9/2011 6:34 PM, Steven D'Aprano wrote:

> Suppose instead an implementation of Python did not pre-compile the
> function. Each time you called spam(n), the implementatio n would have to
> locate the source code and interpret it on the spot. Would that be
> allowed?"
>
> If that's your question, then I would call that a Python interpreter using
> c.1960 technology (as opposed to a byte-code compiler, which all the main
> implementations currently are).
>
> If that were the *only* difference, then I see no reason why it wouldn't be
> allowed as an implementation of Python. A horribly slow implementation, but
> still an implementation.

while and for loops would also be terribly slow if their bodies were not 
compiled but were reinterpreted at the source code level for each loop. 
Having to reinterpred the compiled byte code for each loop does make 
them slower than compiled to native code C. Same as for functions.




More information about the Python-list mailing list