5.1.3 Function Call
The sort of symbolic programs generally written in Common Lisp often
favor recursion over iteration, or have inner loops so complex that
they involve multiple function calls. Such programs spend a larger
fraction of their time doing function calls than is the norm in other
languages; for this reason Common Lisp implementations strive to make the
general (or full) function call as inexpensive as possible. Python
goes beyond this by providing two good alternatives to full call:
- Local call resolves function references at compile time,
allowing better calling sequences and optimization across function
calls. See local-call.
- Inline expansion totally eliminates call overhead and allows
many context dependent optimizations. This provides a safe and
efficient implementation of operations with function semantics,
eliminating the need for error-prone macro definitions or manual
case analysis. Although most Common Lisp implementations support
inline expansion, it becomes a more powerful tool with Python’s
source level optimization. See sections source-optimization
Generally, Python provides simple implementations for simple uses
of function call, rather than having only a single calling convention.
These features allow a more natural programming style:
- Proper tail recursion. See tail-recursion
- Relatively efficient closures.
funcall that is as efficient as normal named call.
- Calls to local functions such as from
- Control transfer is a direct jump.
- The closure environment is passed in registers rather than heap
- Keyword arguments and multiple values are implemented more