Just quickly thinking a little out of the box.

Suppose, that we added grammar for scheme-like symbols. (You know, these atomic identifiers, prefixed with a quote. I don't know much about scheme, but as I understand, they are just constants.)

In Python, the syntax could be similar, we could simply do in a global module scope:

sym symbol

which would translate to:

locals()['symbol'] = Symbol('symbol')

Where Symbol is a built-in that cannot change, which doesn't have a content, except for its name, and never equals anything but itself. From then on, we can access it through the name-binding 'symbol'

Then we could probably create enums, using the classes as we have:

class Colors:
    sym red
    sym green
    sym blue

There are probably some gaps here in my reasoning, but this could also work.

Cheers,
Jonathan



2013/2/12 Tim Delaney <timothy.c.delaney@gmail.com>
On 13 February 2013 09:29, Jonathan Slenders <jonathan@slenders.be> wrote:
Is a new enum keyword still a possibility? To me that seems to be the
cleanest way.

I was just thinking the same. We don't like to have more syntax than necessary, but we should also not introduce too much magic...

That's my conclusion as well. To get a nice* enum with guaranteed semantics and no edge cases, I think it needs parser support.

* for my definition of "nice".

Tim Delaney

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas