What If Python Replaced Elisp?

Neel Krishnaswami neelk at brick.cswv.com
Thu Mar 9 20:46:53 EST 2000


Fredrik Lundh <effbot at telia.com> wrote:
> Samuel A. Falvo II wrote:
> > >umm.  does using an explicit syntax tree turn Lisp
> > >into a statically typed language?
>
> > No, but I don't see what this has to do with the point I was trying
> > to make either.
> 
> then I don't understand your point -- to compile
> things efficiently, you need to know what types
> your variables have.

There are actually a whole lot of optimizations that could be done,
but aren't, in the current Python interpreter.

For example, in the following code:

import operator

lst = []
for i in range(100):
    lst.append(i**2 + i**2)

result = reduce(operator.add, lst) 

You can statically infer the type of result, the final size of lst,
avoid actually allocating a range() object, eliminate the the
typechecks that make sure that i has a __pow__ method, the bounds
checks on the range object, do available expressions analysis on the
i**2 to avoid calculating it twice, and probably a few more
optimizations that I don't know about.

No, these analyses wouldn't help on super dynamic code, but it doesn't
need to to yield big speedups -- most Python code is in the simple
first-order form that is most amenable to analysis.

This is a lot of work, would greatly complicate the internal structure
of the Python implementation, and is a lot of work, and would somewhat
complicate interfacing with C, and is a lot of work, but it's
definitely possible. (*I* have no interest in doing this, not when it
would involve programming in C rather than Python, anyway.)

> in Python, you don't know that, no matter what tree structure or
> byte code format you use.

You don't have to win every game to make it to the championships. :)
 

Neel



More information about the Python-list mailing list