Jussi Piitulainen <harvesting@is.invalid> writes: > dieter writes: >> Chris Angelico writes: >> >>> IMO it's controversial mainly because there's an easy and obvious >>> syntax for early binding, but late binding doesn't have syntactic >>> support, and all the options are imperfect. >> >> I do not think that we should get additional syntax for lately bound >> default values. It would explicitely introduce the concepts early >> versus late binding which are likely difficult to understand by many >> users. > > I'm confused by the term. I don't like it one bit. > > "Early binding" of a default value seems to mean that the expression > that produces the default value of a function parameter is evaluated > when the function is defined. "Late binding" seems to mean that the > expression is evaluated when the function is called. > > In both cases the actual binding of the parameter to the value (either > the default or an actual argument) is established when the function is > called. Several different bindings of that same parameter to different > values can hold simultaneously, so the *binding* has to be conceptually > "late". Because recursion.
Conventionally, "binding" is the association of a "value" with a "name". In this sense, you can call "early binding" the current Python behavior with respect to default parameters: the expression is evaluated into a "value" at function definition time and bound to the parameter name. A later call may rebind the parameter name (if it provides its own value). In the case of "late binding", the function definition would also bind at function definition time the "name" to something (but not a "value"): an expression, maybe together with some binding. This expression would then be evaluated at a later time (and we only then get the typical binding of a "name" to a "value"). > Why isn't the evaluation of the default expression called evaluation? I do not mind if you prefer to use the term "evaluation" instead of "binding". Nothing important in my previous message would be changed by the term exchange: you must specify how (and when) the variables referenced in the expression get their values. And this will give new difficulties - more serious than Python's current handling of default parameters. -- https://mail.python.org/mailman/listinfo/python-list