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

BartC bc at freeuk.com
Wed Jun 8 06:33:15 EDT 2016


On 08/06/2016 10:41, Antoon Pardon wrote:
> 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]

(Did you mean range(4) and [0, 1, 5, 3]?)

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

I can't remember exactly how Pascal worked. But your assignment to B[2] 
is an in-place modification. That sort of thing Python can do (when 
allowed as some things are not mutable) with its existing reference system.

But a 'proper' reference allows a complete replacement of what it refers 
to. That would mean being able to do:

   B = "Cat"
   print A     # "Cat"

No tricks involving in-place updates such as assigning to list elements 
are needed.

-- 
Bartc





More information about the Python-list mailing list