On 2/12/06, Felipe Almeida Lessa <[EMAIL PROTECTED]> wrote: > Em Dom, 2006-02-12 às 23:15 -0500, Steve Holden escreveu: > > Given that Python 2.4 doesn't even perform simple constant folding for > > arithmetic expressions > > [snip] > > May I ask why doesn't it perform such optimization? Is there any special > difficulties in doing so with the Python compiler?
It does in 2.5 thanks to Raymond Hettinger: >>> import dis [18110 refs] >>> def simple(): print 1+2 ... [18136 refs] >>> dis.dis(simple) 1 0 LOAD_CONST 3 (3) 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 0 (None) 8 RETURN_VALUE [18635 refs] >>> Simple, low-hanging fruit like this are covered by the peephole optimizer already. Anything more complex, though, is difficult thanks to things being so dynamic and thus not easy to guarantee to be correct between compile-time and run-time. -Brett -- http://mail.python.org/mailman/listinfo/python-list