Python 1.6 The balanced language
Suchandra Thapa
ssthapa at harper.uchicago.edu
Sat Sep 2 15:18:00 EDT 2000
Tim Roberts <timr at probo.com> wrote:
>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])
The example I gave would be what types of problems that would happen
if python had lazy evaluations. Currently python has eager evaluations so
the code works correctly. The discussion was in the context of extensions to
python.
More information about the Python-list
mailing list