[Python-Dev] Switch statement
Phillip J. Eby
pje at telecommunity.com
Wed Jun 21 19:05:19 CEST 2006
At 06:41 PM 6/21/2006 +0200, Fredrik Lundh wrote:
>Guido van Rossum wrote:
> > (Note how I've switched to the switch-for-efficiency camp, since it
> > seems better to have clear semantics and a clear reason for the syntax
> > to be different from if/elif chains.)
>if you're now in the efficiency camp, why not just solve this on the
>code generator level ? given
> var = some expression
> if var == constant:
> elif var == constant:
>let the compiler use a dispatch table, if it can and wants to.
1. Having special syntax is an assertion that 'var' will be usable as a
dictionary key. Without this assertion, the generated code would need to
trap hashing failure.
2. Having special syntax is likewise an assertion that the 'constants' will
remain constant, if they're symbolic constants like:
FOO = "foo"
More information about the Python-Dev