[Python-Dev] Simple Switch statementZ
Guido van Rossum
guido at python.org
Mon Jun 26 01:23:24 CEST 2006
On 6/25/06, Ka-Ping Yee <python-dev at zesty.ca> wrote:
> On Mon, 26 Jun 2006, Georg Brandl wrote:
> > Raymond Hettinger wrote:
> > > five = 5
> > > eight = 
> > > def f(x, six=6):
> > > seven = 7
> > > a = static(five + 4) # this is legal
> > > b = static(six + 4) # this is illegal
> > > c = static(seven + 4) # this is illegal
> > > d = static(eight + ) # this is illegal
> > Why would the last line be illegal?
> I believe Raymond is assuming it would be illegal because it's mutable.
> I don't think much has been said about whether static(<EXPR>) should be
> allowed to yield a mutable value, but if we did allow that, it might
> open up an avenue to much confusion. (I join the chorus of voices that
> dislike the name 'static' for this feature.)
What do you think of Nick C's 'once'?
> Whether or not 'eight + ' is allowed in 'static', it certainly
> wouldn't be allowed after 'switch' or 'case' since it's unhashable.
Right. But there are all sorts of objects that are compared by object
identity (e.g. classes, modules, even functions) which may contain
mutable components but are nevertheless "constant" for the purpose of
switch or optimization. Let's not confuse this concept of constness
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev