free and nonlocal variables

Jussi Piitulainen jpiitula at ling.helsinki.fi
Thu Mar 21 16:36:09 EDT 2013


Nobody writes:
> On Thu, 21 Mar 2013 01:52:17 -0700, bartolome.sintes wrote:
> 
> > In Python 3, "free variable" and "nonlocal variable" are synonym
> > terms?
> 
> "Free variable" is a computer science term. A variable is free if it
> is not bound. E.g. x and y are free in "x+y", x is bound and y is
> free in "lambda x: x+y", x and y are both bound in "lambda y: lambda
> x: x+y". IOW, a variable is free in an expression if the expression
> doesn't include whatever created the variable.

And in (lambda x : x)(x) + x below, x occurs both free and bound. The
free occurrences are bound by the outer lambda.

   >>> (lambda x : (lambda x : x)(x) + x)(3)
   6



More information about the Python-list mailing list