What is a function parameter =[] for?

Marko Rauhamaa marko at pacujo.net
Wed Nov 25 09:08:26 EST 2015


Chris Angelico <rosuav at gmail.com>:

> On Wed, Nov 25, 2015 at 11:48 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> I think "binding" is too fancy a word to be used with conventional
>> programming languages like Python. If your programming language has
>> an assignment statement, "binding" is even nonsensical. Consider:
>>
>>    def f(x):
>>        x += 1
>>        return 2 * x
>>
>> Now we would have this reduction:
>>
>>    f(7)
>>    =>
>>    7 += 1; return 2 * 7
>>
>> because "x" would be bound to "7" everywhere in the function body.
>
> This is exactly the sort of problem that inevitably happens when you
> try to extend mathematics into programming. Most branches of
> mathematics are simply looking at pure, eternal statements of truth;
> if once you discover (or decide) that x is equal to 7, you can
> perfectly substitute one for the other in any context. There is no
> chronology - x has always been equal to 7, you just didn't know it
> until now. It's possible to write code this way, and there are
> benefits to it, but as soon as you have an assignment operator, you're
> introducing a whole aspect of chronological truth that math lacks, so
> some concepts ARE going to need to be modified.
>
> However, that doesn't stop us from making use of terminology, where
> it's helpful.

I think that's the point. Binding is a concept of a formal (textual)
substitution algorithm, which Python's assignment is not.

   Variable-binding mechanisms occur in different contexts in
   mathematics, logic and computer science. In all cases, however, they
   are purely syntactic properties of expressions and variables in them.

   <URL: https://en.wikipedia.org/wiki/Free_variables_and_bound_variable
   s#Formal_explanation>


Marko



More information about the Python-list mailing list