What is a function parameter =[] for?

Marko Rauhamaa marko at pacujo.net
Wed Nov 25 07:48:21 EST 2015


Jussi Piitulainen <harvest at should.be.invalid>:

> In point d, McCarthy refers to variables as variables; I'm sure this
> would go back to Church and 1940's at least, so I expect they used
> this word already back then. But the ability to store new content to
> the data structure that associates variables with stuff must be newer.
> I think it was new with LISP.

As far as the words "variable" and "binding" go, they are present in
lambda calculus (1929 and on):

   Lambda calculus (also written as λ-calculus) is a formal system in
   mathematical logic for expressing computation based on function
   abstraction and application using variable binding and substitution.
   First formulated by Alonzo Church [...]

   [...]

   The abstraction operator, λ, is said to bind its variable wherever it
   occurs in the body of the abstraction. Variables that fall within the
   scope of an abstraction are said to be bound. All other variables are
   called free.

   <URL: https://en.wikipedia.org/wiki/Lambda_calculus>

In lambda calculus, variables are formal markers that are used during
substitution during reduction (ie, evaluation).

If we were to apply the thinking to Python, we could have:

   def f(x):
       return (x + 3) * x

   def g(x):
       return x * 2 - math.sqrt(x)

Now the Python expression

   f(g(7))

could be reduced as follows:

   f(g(7))
   =>
   (g(7) + 3) * g(7)
   =>
   ((7 * 2 - math.sqrt(7)) + 3) * (7 * 2 - math.sqrt(7))
   =>
   (7 * 2 - 2.6457513110645907) + 3 * (7 * 2 - 2.6457513110645907)
   =>
   [etc]
   
That is, binding/substitution is syntactic/formal. Or, to say it in
another way, lambda calculus is a kind of macro processing language like
cpp or m4.

> I don't know if assignment was originally called assignment, or whether
> the association of names with stuff was originally called binding, but
> this terminology is old enough that I've known binding and assignment of
> variables by these names for as long as I can remember, with more or
> less the semantics that Python now uses. "Rebinding" I've not known
> elsewhere.

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.


Marko



More information about the Python-list mailing list