functions, list, default parameters
hniksic at xemacs.org
Wed Nov 3 10:31:18 CET 2010
Paul Rudin <paul.nospam at rudin.co.uk> writes:
> Terry Reedy <tjreedy at udel.edu> writes:
>> Suppose I write an nasty C extension that mutates tuples. What then
>> would be illegal about...
> Depends on exactly what we mean by legal. If immutability is part of the
> language spec (rather than an artifact of a particular implementation)
> then a compiler could assume immutability.
And, indeed, it does exactly that. Tuples of constant literals are
created at compilation time and reused across function invocations.
Mutating a tuple using a C extension is "illegal" in that it breaks the
rules of the system, by changing the semantics of valid code in
unexpected ways. A more extreme example of this would be mutating the
constant 0 or the empty tuple.
More information about the Python-list