What is a function parameter =[] for?

Chris Angelico rosuav at gmail.com
Wed Nov 25 08:50:59 EST 2015


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. We know from grade school that adding two numbers
together and dividing by 2 gives us the average, or the midpoint
between them. Programming languages introduce the notion of adding two
strings together, and also throw the curve-ball at us that sometimes
the average isn't the same as the perfect mathematical average (due to
rounding or other issues). But we'll still call that operation adding,
and we'll still have avg() functions that do what we broadly expect.

ChrisA



More information about the Python-list mailing list