[Python-Dev] Switch statement (original) (raw)

Fredrik Lundh fredrik at pythonware.com
Mon Jun 12 00:44:50 CEST 2006


Talin wrote:

I don't have any specific syntax proposals, but I notice that the suite that follows the switch statement is not a normal suite, but a restricted one, and I am wondering if we could come up with a syntax that avoids having a special suite.

don't have K&R handy, but I'm pretty sure they put switch and case at the same level (just like if/else), thus eliminating the need for silly special suites.

The only real difference between this and an if-else chain is that the compiler knows that all of the test expressions are constants and can be hashed at compile time.

the compiler can of course figure that out also for if/elif/else state- ments, by inspecting the AST. the only advantage for switch/case is user syntax...



More information about the Python-Dev mailing list