[Python-Dev] Switch statement
Phillip J. Eby
pje at telecommunity.com
Mon Jun 19 05:59:21 CEST 2006
At 06:56 PM 6/18/2006 -0700, Josiah Carlson wrote:
>The non-fast version couldn't actually work if it referenced any names,
>given current Python semantics for arbitrary name binding replacements.
Actually, one could consider "case" expressions to be computed at function
definition time, the way function defaults are. That would solve the
problem of symbolic constants, or indeed any sort of expressions.
An alternate possibility would be to have them computed at first use and
Either way would work, and both would allow multiple versions of the same
switch statement to be spun off as closures without losing their "constant"
nature or expressiveness. It's just a question of which one is easier to
explain. Python already has both types of one-time initialization:
function defaults are computed at definition time, and modules are only
loaded once, the first time you import them.
More information about the Python-Dev