Functional programming gotcha

Georgy Pruss SEE_AT_THE_END at hotmail.com
Fri Oct 24 23:11:52 EDT 2003


"Terry Reedy" <tjreedy at udel.edu> wrote in message news:WY2dnVQZG8eMKgSiRVn-iA at comcast.com...
>
> <...>
>
> Others have given the solution, but let's think about the why of it.
> If a function in a dyanamic language (one that allows runtime
> construction of functions) has a free variable (one not set within the
> function), the question arises "When do we get (capture) the value of
> the variable?  At definition/construction time or at call/execution
> time?  Or, to put it another way, what do we capture?  The (current)
> value of the variable or its name (for later evaluation).  Either
> could be what we want.
>
> Python lets you choose which capture method (evaluation time) you
> want.  Do nothing to get the name captured for later evaluation.  Or
> put v=v in the arglist to capture the current value and give it the
> same name (w=v, to use a new name, is legal too, of course).
>
> Terry J. Reedy
>

Very good and simple explanation! Thank you.

Georgy







More information about the Python-list mailing list