I'm wrong or Will we fix the ducks limp?

Antoon Pardon antoon.pardon at rece.vub.ac.be
Wed Jun 8 05:41:20 EDT 2016


Op 08-06-16 om 10:47 schreef Steven D'Aprano:
> On Wednesday 08 June 2016 17:53, Antoon Pardon wrote:
>
>> Python could go the simula route, which has two kinds of
>> assignment. One with the python semantics and one with C
>> semantics.
>>
>> Let as use := for the C sematics assignment and <- for the
>> python sematics assignment. We could then do something like
>> the following.
>>
>> ls := [5, 8, 13, 21]
>> a <- ls[2]
>> a := 34
>> print ls  # [5, 8, 34, 21]
> What you seem to be describing is similar to reference parameter semantics from 
> Pascal. Assignment doesn't work that way in C, or Python.

I disagree. In python the assignment does work similar to the reference parameter
semantics in pascal. See the following

  A = range[4]
  B = A
  B[2] = 5
  print A # [0, 1, 5, 2]

This is exactly the result you would get with B as a reference parameter in pascal.

> And of course Python doesn't have reference variables either. There is nothing 
> you can do in Python to get this effect:
>
> a = 1
> b = a
> b = 99
> assert a == 99

It is true that you can't get such an effect in python, but that doesn't imply
that python doesn't have reference variables (as an abstract notion). Because
having reference variables doesn't imply you can have that effect. If all
you have is reference variables and assignments just change what object is refered
to, you can't have such an effect either.

-- 
Antoon Pardon.



More information about the Python-list mailing list