Call by binding [was Re: [Tutor] beginning to code]
Marko Rauhamaa
marko at pacujo.net
Mon Sep 25 08:16:52 EDT 2017
Antoon Pardon <antoon.pardon at vub.be>:
> Op 25-09-17 om 13:32 schreef Marko Rauhamaa:
>> In Python, assignment "mutates the target" as well. It's only that in
>> Python, the target is always a pointer.
>
> Fine if you want to word it like that, the assignments in Pascal and
> Python are still sufficiently different.
>
> If you do A := B in Pascal, you have two different entities with equal
> values.
>
> If you do A = B in Python, you have one entity that is refered to by
> two variables/names.
Python only operates with pointers. You can operate with pointers in
Pascal as well.
Say I have (in Pascal):
new(A);
B := A
Then, in Pascal, you have one entity that is referred to by two
variables/names.
> The difference becomes clear if you later mutate A or B. In the case
> of Pascal, you will have mutated one of two entities and the other
> entity remains the same. In the case of Python, you will have mutated
> the one entity that both A and B refer to and so the mutations will be
> visible through the other variable/name.
Continuing the Pascal example above:
new(A);
B := A; { one entity, two names }
A^ := 3; { mutate the one entity }
writeln(B);
A^ := 7; { mutate the one entity again }
writeln(B)
will output
3
7
(although I haven't programmed anything in Pascal for than 30 years so
my syntax may be off).
Marko
More information about the Python-list
mailing list