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

Python preprocessor

Name: Anonymous 2006-11-30 5:28

I'm considering writing a Python preprocessor that will parse Python code "with stuff" and write real Python code, to add to Python what many want, at the cost of reserving all names starting with four underscores (I doubt you'll need these). I'm considering of supporting the following, but I'm interested on hearing comments, feedbacks, etc. Also, if you're interested on doing this, go for it, I may take a long time as I have little spare time.

1. Support for inline def (anonymous block closures) like:
#We call hello(int, function, int) with a new anonymous block closure as follows:
hello(1, def (x):
        ...code of anonymous closure...
, 2) #Starts in the same column as hello


2. More comfortable if..else (with flawless workaround for Python < 2.5): iff (cond) (expr_true) (expr_false)

3. Switch:
switch expr:
        case expr1:
                block
        case expr2:
                block
        default: #Optional
                block


4. Do..while:
do:
        block
while cond


5. until expr = while not (expr), serves for both while and do..while blocks

6. /* ... */ comments, as in C

7. q{ ... } and q[ ... ] quotes with recursive {} or [] matching (e.g. q[a['k']="v"] is fine), as in Perl; q{} and q[] for str strings and u{} and u[] for unicode strings

8. Alternate syntax for decorators: instead of:
        @staticmethod
        def mymethod():
you can simply do:
        @staticmethod mymethod():

9. swap statement to exchange the value of two lvalues: swap x y

10. defined() special function which returns whether an identifier has been defined or not (like isset) without raising an exception

11. Optionally enabled: ? becomes an alias to lambda, so ?x: x + 1 is equivalent to lambda x: x + 1

12. Optionally enabled: automatic Unicode conversion: str to unicode, '' to u'', q{} to u{}, etc.





Name: Anonymous 2006-11-30 5:34

BTW, if you have a good reason against doing any of the points, let me know, though skip the Pythonic ones (1. We can do def tmp, then use tmp; 2. Can be done with a function; 3. Can be done with if-else; 4-5. Can be done with while; 6. Can be done with # or '''; 7. Use ' \' \\\' \\\\\\\' hell; 8. Meh; 9. Can be done with tmp=a;a=b;b=tmp; 10: Can be done with try..except; 11: Looks ugly; 12: Coming in Python 3000). In particular, for the "Can be done" stuff: unless you have a way that's simpler and clearly superior, remember everything can also be done in C. As for other reasons (or additions), I'm very open to suggestions.

Name: Anonymous 2006-11-30 9:06

Lisp macros.

Name: Anonymous 2006-11-30 9:34

>>3
I don't know Lisp; could you post a short explanation and example of how they work? If I find how they may be implemented in Python, I could include them.

Name: Anonymous 2006-11-30 14:00

Name: Anonymous 2006-11-30 18:29

These look useful (although I wonder about maintainability), but they will be difficult to implement; if my preprocessor gets done, it won't have macros in the first version.

Name: Anonymous 2006-12-01 5:13

>>6
They'll be just about impossible to implement for Python because Lisp macros rely on a language that has a simple homoiconic syntax.

Name: Anonymous 2006-12-03 4:08

>>7
hehe, he said "homo"...

Name: Anonymous 2006-12-03 10:13

>>7
Perl 6 has macros, it can change it's own grammar somehow i don't know the details. So I doubt that it will be just about impossible for Python.

Name: Anonymous 2006-12-03 11:14

>>9
Yes but perl macros are flaky in the same way C macros are; because they operate on text instead of an AST it's very difficult to get them to work the way you want them to.

Name: Mutiny 2006-12-05 19:15

PREPROCESSORS ARE UNPYTHONIC

Name: Anonymous 2006-12-05 21:48

>>11
I know I'm an heretic, and some of the features I proposed are unpythonic, but I want to have the best language, not necessarily the most pythonic language.

Name: Anonymous 2006-12-06 6:43

>>12
Then Python is not for you.

Name: Anonymous 2006-12-06 7:02

>>13
I chose it because it's the closest to my ideal language. So it is for me.

Name: Anonymous 2009-01-14 13:17

SICP

Name: Anonymous 2009-01-14 13:18

WRITE UR OWN LANGUAGE FAG

Name: Anonymous 2009-02-25 7:56


fancy F7 is for   enterprise faggots RTF?

Name: Anonymous 2009-03-06 6:09

The first is bigger   Then the same   manner some sort   of idea how   to do it   with mod alias   might be an   expert on the   system can share.

Name: Sgt.Kabu鲱䶏kiman 2012-05-28 21:06

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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