Am I the only one who would love these extentions? - Python 3.0 proposals (long)

Peter Otten __peter__ at web.de
Mon Nov 10 12:56:30 EST 2003


Georgy Pruss wrote:

> I would like to propose some extentions to the language, probably

...

> 5) Enum type. Introduces global (module-level) constants of
> number or string values. The numeric values can be assigned
> automatically like in the C language. If the enum declaration
> has a name, this name defines "a namespace" and it must be
> specified for referring to the values.
> 
>    # defines constants AXIS.X=0, AXIS.Y=1,  AXIS.Z=2
>    enum AXIS: X, Y, Z
> 
>    # defines color.red, color.green, color.blue
>    enum color
>       red = '#FF0000', green = '#00FF00', blue = '#0000FF'
> 
>    # defines consts A=0, B=1, C=2, D=10, E=11, F=12
>    enum
>      A, B, C
>      D = 10, E
>      F
> 
>    # the same as above
>    enum: A; B, C, D=10; E, F # ';' and ',' are the same here.

enum WhosAfraidOf:
    red
    yellow
    blue

for color in WhosAfraidOf:
    barnetPaintsItIn(color)
>>> len(WhosAfraidOf)
3

I would like something along these lines. I think you omitted the most
important benefit, getting the names rather than the values, which I'm
looking forward to, so I will shamelessly copy from a recent conversation
on Python-Dev:

[quote]
> > I would love it if what happened really was something like:
> >
> >>>> from socket import *
> >>>> print AF_UNIX
> > socket.AF_UNIX
> >>>> from errno import *
> >>>> print EEXIST
> > errno.EEXIST
> 
> I've had this idea too.  I like it, I think.  The signal module could
> use it too...

Yes, that would be cool for many enums.
[end quote]

(I do not follow the list closely, but I think there was no talking of a new
syntax for enums, though)

> 6) The colon is optional after for,if,try,enum etc. if it is
> followed by a new line. Although it's mandatory if there are
> statements on the same line. So it's like ';' -- you MUST
> use it when it's needed. You CAN still use it if you like it,
> like now you can put a semicolon after each statement
> as well.
> 
>    def abs(x)
>       if x < 0
>          return -x
>       else
>          return x

While I forget the colon more often than I'd like to, this is mostly a
non-issue as it is caught by the compiler and does no runtime harm. Also,
the colon would make the above example slightly more readable.

> 11) Unconditional loop. Yes, I'm from the camp that
> finds 'while 1' ugly. Besides, sometimes we don't need
> a loop variable, just a repetition.
> 
>    loop [<expr_times_to_repeat>]
>       <stmts>

Not sure. Maybe

while:
    repeatThisForever()

> 16) Depreciated/obsolete items:
> 
> -- No `...` as short form of repr();
> -- No '\' for continuation lines -- you can always use parenthesis;

Yes, away with these!

> -- No else for while,for,try etc -- they sound very unnatural;

I'm just starting to use else in try ... except, so my resistance to the
extra else clauses is not as strong as it used to be...

> -- Ellipsis -- it looks like an alien in the language.

What the heck is this? The Nutshell index does not have it, and I couldn't
make any sense of the section in the language reference.


Peter






More information about the Python-list mailing list