On 6/25/06, Ka-Ping Yee <[EMAIL PROTECTED]> wrote:
> On Mon, 26 Jun 2006, Georg Brandl wrote:
> > Raymond Hettinger wrote:
> > >    five = 5
> > >    eight = [8]
> > >    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 + [4]) # 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 + [4]' 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
with immutability.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to