Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python Code Contraction

Name: Anonymuus 2011-05-15 2:50

Working on python code, there are a few ways to contract code:
print 'hi'
print 'ho'

can be written as:
print 'hi';print 'ho'

something like
for i in range(9):print i
is perfectly like acceptable in one line, yet these don't work for one reason or another:
print 'hi';for i in range(9):print i
for i in range(9):if i != 8:print i
if i != 8: print i;else:print 'no'

because nesting a loop or a condition anywhere but the beginning of a line gives a syntax error.
Is is possible any other way?

Name: Anonymous 2011-05-15 3:28

you're a fucking idiot

Name: Anonymous 2011-05-15 3:40

What >>2-san said.

Name: Anonymous 2011-05-15 3:50

lol

Name: Anonymous 2011-05-15 3:52

print 'hi';for i in range(9):print i
Why would you want to do this?

Name: Anonymous 2011-05-15 4:10

>>5
it's an example, just like this:
anakin = 20;if anakin+obi == 40:order66()

it could make a lot of my code a lot more manageable.

Name: Anonymous 2011-05-15 4:14

>>6
it could make a lot of my code a lot more manageable.
What?

Name: Anonymous 2011-05-15 4:30

MANAGE MY ANUS

Name: Anonymous 2011-05-15 5:59

>>6 it looks, like you want to use code indentation, to express, that some data is strictly bound to some computations. It can be elegantly expressed in Haskell by using let construction:

Prelude>let x=9; y=99 in x+y

Name: Anonymous 2011-05-15 5:59

FV detected

Name: JAVASCRIPTTER 2011-05-15 6:21

>>9
{var x=9,y=99; return x+y;}

Name: PERLLER 2011-05-15 7:27

>>9,11
108

Name: CER 2011-05-15 7:34

>>9,11,12

#include <stdio.h>
#define EVALUATOR(a, b) a; b

int main(){
    int c;
    EVALUATOR(c, {int a = 9; int b= 99; c=a+b;} );
    printf("%d\n", c);
}



Macro is redundant, but it makes code prettier.

Name: Anonymous 2011-05-15 8:30

>>1
They are called FORCED ONE-LINERS TO AVOID THE FORCED INDENTATION OF CODE.

Name: Anonymous 2011-05-15 10:13

Python Code Contraction Camp

Name: Anonymous 2011-05-15 10:45

>>1
What is this gay?

Name: Anonymous 2011-05-15 11:34

>>15
Code Contraction Camp for Python, comrade.

Don't change these.
Name: Email:
Entire Thread Thread List