Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99198

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)

From dieter <dieter@handshake.de>
Newsgroups comp.lang.python
Subject Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)
Date 2015-11-21 08:26 +0100
Message-ID <mailman.30.1448090833.2291.python-list@python.org> (permalink)
References <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <mailman.508.1448005763.16136.python-list@python.org> <lf5bnapm4xa.fsf@ling.helsinki.fi>

Show all headers | View raw


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.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) dieter <dieter@handshake.de> - 2015-11-20 08:49 +0100
  Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) Jussi Piitulainen <harvesting@is.invalid> - 2015-11-20 10:49 +0200
    Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) dieter <dieter@handshake.de> - 2015-11-21 08:26 +0100

csiph-web