Nested function scope problem
Terry Reedy
tjreedy at udel.edu
Tue Jul 25 12:56:10 EDT 2006
"Dennis Lee Bieber" <wlfraed at ix.netcom.com> wrote in message
news:7fnbc21742p5kcfis5b9sobtsvvqmmm98v at 4ax.com...
> The names in the parameter list of the "def" statement are bound to
> the objects associated with the actual call. After that, they behave
> very much as locals... Now -- with defaults it gets a touch trickier...
A function's parameters are not just 'very much as locals', they *are*
locals.
>>> def f(x): print locals()
>>> f(3)
{'x': 3}
In particular, parameters are just those locals that are initialized in the
call process; it is an error for a parameter name to not become bound to
some object. The default objects fill in the slack when there are not
enough argument objects.
>From the calling side, the arguments are objects to be used in that initial
binding process, either directly or as part of a new collective object. It
is an error for an argument to not be used. The calling code does not care
about the parameter names, but just their number and nature.
So one can think of calling as cross-namespace name binding followed by
control transfer. Returning is similar except that return objects may
ignored or bound to slots rather than names.
Terry Jan Reedy
More information about the Python-list
mailing list