Another stab at a "switch/case" construct (for Python 3000):

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Thu Mar 28 12:31:15 EST 2002


I like it.

You *have* to allow variables in the match list, however, plus objects
that evaluate to a suitable value or sequence of values. There's no
reason why the compiler couldn't detect and optimise the case where
only constants are used.

I prefer 'else' to 'any' - a lot. I makes more sense and doesn't need
a new keyword.

As for the name, 'match'? Given that it would cause problems with the
're' module, how about a name that is invalid syntax at the moment.
What about names with spaces? 'match on'? 'switch on'? 'select from'?
It would give the syntax analyser something to think about but
wouldn't break any code. Such a scheme would allow all sorts of safe
expansions.

Alternatively, capitalise Java-style: 'matchOn' or 'switchOn'

I know I'm supposed to ignore it but I'd also like to support the
addition of UNTIL and UNLESS as alternatives for WHILE NOT and IF NOT.
I whince every time I have to reverse the logic of a test just to suit
the restrictive syntax of the langage.

--
Dale Strickland-Clark
Riverhall Systems Ltd



More information about the Python-list mailing list