Assignment versus binding

dieter dieter at handshake.de
Tue Oct 4 03:17:19 EDT 2016


Steve D'Aprano <steve+python at pearwood.info> writes:
> On Mon, 3 Oct 2016 04:15 pm, Jussi Piitulainen wrote:
>> Steve D'Aprano writes:
>>> Why shouldn't people say that binding and assignment are the same
>>> thing in Python? What's the difference?
>> 
>> Outside Python, (lambda x : f(x)) is said to "bind" x. It's different
>> from assigning a new value to x. It's similar to how quantifiers in
>> logic are said to bind their variables, so that variables bound to
>> different quantifiers are different variables.
>
> o_O
>
> Me: "How is binding different from assignment?"
>
> You: "This is an example of binding: lambda x: f(x). Its different from
> assigning to x. Clear now?"
>
>
> What's "outside python"?

The concept "assignment" comes from an operational semantics based
on some form of "RAM" machine. Such a machine has storage cells where
you can assign values to which remain there until overridden with
a new value.

The concept "binding" comes from a denotational semantics based on
some form of functions where parameter names are bound to values on
function "application" and do not change inside the function.


When you pass a Python variable as parameter to a function,
and this function modifies the value of the corresponding
"formal parameter", this does not change the variable's value.
This indicates, that the variable does not model directly the
corresponding storage cell.

On the other hand, you can assign a new value to a Python variable
which indicates that Python variables are neither simple bindings.


Of course, these are only semantic subtlenesses.

There are storage cells associated with Python variables and assignment
can change their content (only on function call, it is not the storage
cell that gets passed on into the function but the current value).

On the other hand, one can model Python variables as bindings
where language constructs (assignments) allow to change the binding.

Thus, at an appropriate level of abstraction, you can say that
"binding" and "assignment" are mostly equivalent.




More information about the Python-list mailing list