Call by binding [was Re: [Tutor] beginning to code]

Antoon Pardon antoon.pardon at vub.be
Mon Sep 25 08:05:40 EDT 2017


Op 25-09-17 om 13:32 schreef Marko Rauhamaa:
> 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.

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.

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.

-- 
Antoon Pardon.




More information about the Python-list mailing list