Python 1.6 The balanced language

Tim Roberts timr at probo.com
Fri Sep 1 07:22:43 CEST 2000


ssthapa at harper.uchicago.edu (Suchandra Thapa) wrote:
>With python's lack of referential
>transparency, this will become a nightmare.  E.g.
>    def swap(x, y):
>	t = y[x - 1]
>	y[x - 1] = x
>	x = t
>	print x','y[x-1]
>
>    x = 3
>    y = [3, 2, 1]
>    swap(x, y)
>
>prints 3 , 3 which is probably not the programmer intended.

When I type this into Python 1.5.2, I get 1 , 3.  This is what I expected.
The outer value of x is not altered, although y is.  Is that what you're
referring to?

 >>> swap(x,y)
 1 , 3
 >>> x,y
 (3, [3, 2, 3])

--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list