[Python-Dev] Switch statement
Nick Coghlan
ncoghlan at gmail.com
Wed Jun 21 12:34:12 CEST 2006
Greg Ewing wrote:
> Phillip J. Eby wrote:
>
>> 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.
>
> That's an excellent idea!
>
>> It's just a question of which one is easier to explain.
>
> I think the function-definition-time one is easiest to
> both explain and also to reason about when writing code,
> since definition time is well-defined, whereas "the first
> time it's executed" is somewhat fuzzy.
There's some benefit to "first time it's executed" though:
a. it allows access to the local namespace
b. it uses the same semantics at module level as it does in a function
If we go with 'at function definition time', then neither of those is true.
I'm actually curious how a module level switch statement would work at all in
that case, without either falling back on the "first time it's executed"
definition, or else not permitting switch statements in module level code.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list