Call by binding [was Re: [Tutor] beginning to code]
Marko Rauhamaa
marko at pacujo.net
Mon Sep 25 07:32:56 EDT 2017
Antoon Pardon <antoon.pardon at rece.vub.ac.be>:
> Op 25-09-17 om 11:41 schreef Marko Rauhamaa:
>> Antoon Pardon <antoon.pardon at vub.be>:
>>
>>> the semantics of an assignment depends on the language
>> I've only seen one kind of assignment in the general-purpose
>> programming languages I know, maybe with the exception of Prolog and
>> Rust.
>
> I disagree. In languages like Pascal an asignment mutates the target
> that the left hand refers to, by copying over the value from the right
> side. In languages like python an asignment lets the target refer to a
> new entity.
In Python, assignment "mutates the target" as well. It's only that in
Python, the target is always a pointer.
Here's proof (up to isomorphism):
>>> x = object()
>>> y = object()
>>> id(x)
139719622467712
>>> x = y
>>> id(x)
139719622467728
Meaning. Before:
+---------- x ----------+
| 139719622467712 |
+-----------------------+
After:
+---------- x ----------+
| 139719622467728 |
+-----------------------+
So we can see the contents of x have been mutated.
Marko
More information about the Python-list
mailing list