suggestion: swap function in Python
Skip Montanaro
skip at pobox.com
Thu May 31 16:37:55 EDT 2001
Nick> suggested syntax for a 'swap' statement:
Nick> a = 10
Nick> b = 20
Nick> swap a b
This, as you observed, would break code that uses swap as an identifier.
That, coupled with the fact that it is less expressive than tuple unpacking
which can do much more glorious things like
(a,b,c) = (1,2,3)
would almost certainly doom the proposal. If you need it to be atomic (the
only possible reason I can see for implementing this idea), you'd have to
define a new opcode for the Python VM. That's not hard to do, but the
interpreter's main loop is already large, and this would just make it more
cache-bustingly huge.
--
Skip Montanaro (skip at pobox.com)
(847)971-7098
More information about the Python-list
mailing list