Python compilers?

Heather Coppersmith me at privacy.net
Wed May 19 19:08:21 EDT 2004


On 19 May 2004 14:54:48 -0700,
imbosol at aerojockey.com (Carl Banks) wrote:

> Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote in message
> news:<7xad0581ax.fsf at ruckus.brouhaha.com>...

>> Carl Banks <imbosol at aerojockey.invalid> writes:

>> > I don't follow you.  In what way is Python dynamic that Lisp isn't?
>> 
>> 
>> >>> class foo:
>> ...   def bar(self, x):
>> ...     return x*x
>> ... 
>> >>> a = foo()
>> >>> a.bar(3)
>> 9
>> >>> a.bar = lambda x: x*x*x
>> >>> a.bar(3)
>> 27
>> >>>

> Well, come on, of course there's going to be some things here
> and there you can do in one and not the other.  In wat is Python
> dynamic that Lisp isn't to such an extent that it would cripple
> any attempts to compile it?

It's not a matter of not being able to compile python; it's a
matter of what sort of benefits you'd gain.

For example:

    if x.y.z == a.b.c:
        print 'equal'

What is x.y.z?  Who knows?  The object to which x is bound might
create y on the fly, based on information not available to the
compiler (see __getattr__ and properties).  Once the run-time
system asks object x for attribute y, it (the run-time) has to go
through the whole process again to determine z (and, therefore,
x.y.z).  Similar for a.b.c, and any of that code might have
redefined what it means for such objects to be equal, which means
that the compiler can't even know what sorts of equality tests
might be available at the time that the code executes, let alone
generate a simple compare instruction.

This is important:  There is little, if any, difference between
that code and running everything through the interpreter anyway.

For that matter, simply accessing x.y might change a.b.  (FWIW,
though, the ensuing programmer-cide would be entirely justified.)

"Plain" Common Lisp code has (mostly) the same issues, but
performance critical Common Lisp programs contain strategically
placed type declarations (thus reducing the dynamicity of the
language) to help the compiler to know what it's up against.

There are proposals to add type declarations to Python; google is
your friend (see also 'decorators').  Similar for JIT compilers
(psyco falls into this category).

Regards,
Heather

-- 
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli



More information about the Python-list mailing list