[Python-Dev] Switch statement (original) (raw)
Fredrik Lundh fredrik at pythonware.com
Wed Jun 21 19:53:42 CEST 2006
- Previous message: [Python-Dev] Switch statement
- Next message: [Python-Dev] Switch statement
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Guido van Rossum wrote:
But in most cases the 'constant' is actually an expression involving a global, often even a global in another module. (E.g. srecompile.py) The compiler will have a hard time proving that this is really a constant, so it won't optimize the code.
unless we come up with a way to make it possible to mark an variable as a constant.
The proposed switch semantics (create the table when the containing function is defined) get around this by "defining" what it means by "constant".
well, given that people find it really confusing that the two X:es in
def func(value=X):
print X
are evaluated at different times, I'm not sure it's a good idea to introduce more "evaluation scopes".
but sure, I'm sure people doing certification tests would love questions like:
Q: If a program calls the 'func' function below as 'func()'
and ONE and TWO are both integer objects, what does 'func'
print ?
ONE = 1
TWO = 2
def func(value=ONE):
switch value:
case ONE:
print value, "is", ONE
case TWO:
print value, "is", TWO
a: "1 is 1"
b: "2 is 2"
c: nothing at all
d: either "1 is 1" or nothing at all
e: who knows ?
but I cannot say I find it especially Pythonic, really...
- Previous message: [Python-Dev] Switch statement
- Next message: [Python-Dev] Switch statement
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]