Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lisp vs Python -- Static Compilation

Why can Lisp with all its dynamic features be statically compiled but Python cannot (without losing all its dynamic features)?

like image 398
yodie Avatar asked May 11 '10 17:05

yodie


People also ask

Is Common Lisp faster than Python?

Processing is slower in the Lisp Programming language when compared to the Python programming language. Processing is faster in Python programming language when compared to Lisp Programming language. Lisp Programming language is not preferred much to work on Artificial Intelligence.

How Fast Is Common Lisp?

Common Lisp is AOT compiled to the metal so it starts up fast and runs fast. CL is often within a factor of 2 of C speed and dramatically faster than plain Python.


2 Answers

There is nothing that prevents static compilation of Python. It's a bit less efficient because Python reveals more mutable local scope, also, to retain some of the dynamic properties (e.g. eval) you need to include the compiler with the compiled program but nothing prevents that too.

That said, research shows that most Python programs, while dynamic under static analysis, are rather static and monomorphic at runtime. This means that runtime JIT compilation approaches work much better on Python programs. See unladen-swallow, PyPy, Psyco for approaches that do compile Python into machine code. But also IronPython and Jython that use a virtual machines originally intended for a static languages to compile Python into machinecode.

like image 73
Ants Aasma Avatar answered Oct 05 '22 12:10

Ants Aasma


For what its worth, Python scripts are compiled into .pyc files when the are executed, see "Compiled" Python files.

You can also use a tool such as py2exe to compile a Python program into an executable.

like image 43
Justin Ethier Avatar answered Oct 05 '22 11:10

Justin Ethier