Clever One Liners

holger krekel pyth at devel.trillke.net
Thu Jul 3 05:01:45 EDT 2003


Curly Joe wrote:
> I agree with you, especially since the compiler, in
> most cases, must break everything down into single
> steps anyway.  Take for instance a very simple
> example:
> x = a + b/c
> The compiler would execute this as:
> x = b/c
> x += a

to be more precise, the compiler would *compile*

    x = a + b/c

to some bytecode like

      LOAD_FAST                0 (a)  # get var and put on valuestack
      LOAD_FAST                1 (b)  # get var and put on valuestack
      LOAD_FAST                2 (c)  # get var and put on valuestack
      BINARY_DIVIDE                   # take 2 stack values and put 
                                      # the devision of them on valuestack
      BINARY_ADD                      # take 2 stack values and put 
                                      # the sum on the value stack
      STORE_FAST               3 (x)  # store last stack item into "x"

and the interpreter would execute this bytecode. 

> Michael Chermside wrote:
> I'm not picking on you in particular, there have been
> several people
> doing this lately, but I'd like to ask folks to please
> lay off the
> quest for one-liners.

What about going for writing bytecode-assembler instead of 
language-level oneliners :-) ? 

cheers,

    holger





More information about the Python-list mailing list