static variables?

Erik Max Francis max at alcyone.com
Wed Nov 20 02:02:11 EST 2002


Chad Netzer wrote:

> So, since the default argument is part of the definition, the default
> argument is actually created and bound, once, during the definition,
> not
> repeatedly during calling.

Oh, of course; there's really no question why this is the case in the
current implementation.  My point is that there is no real a priori
reason why mutable default arguments couldn't do the equivalent of

	def f(x=None):
	    if x is None:
	        x = SomethingMutable
	    ...

[For those about to mention the "But what if you really want x to be
None?" objection, one can simply use a private sentinel object.]  I
don't see a real compelling reason why, if you were to design a language
from scratch, you _wouldn't_ want this behavior -- given the unending
amount of confusion this feature causes.  (There are certainly reasons
to use it, but in my opinion there are clearer ways to get the same
effect.)  It's pretty obvious why it was done in the implementation --
because it's the easiest obvious implementation -- but there's no reason
in and of itself that it _must_ be done that way.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Seat thyself sultanically among the moons of Saturn.
\__/ Herman Melville
    Official Omega page / http://www.alcyone.com/max/projects/omega/
 The official distribution page for the popular Roguelike, Omega.



More information about the Python-list mailing list