syntax for preset locals without using dummy args with defaults

Bengt Richter bokr at oz.net
Fri Jan 10 23:12:11 EST 2003


On Fri, 10 Jan 2003 18:15:00 -0500, "Terry Reedy" <tjreedy at udel.edu> wrote:

>
>"Bengt Richter" <bokr at oz.net> wrote in message
>news:avmoeu$v8p$0 at 216.39.172.122...
>> Yet another idea ;-)
>>
>> Right now we often see
>>
>>     def foo(x, y=default, z=some_expression):
>>         ...
>>
>> where the purpose is not to have three parameters, but two
>> plus a local binding (z) in foo to the value of some_expression
>> evaluated in the def-time environment. z may bind something not
>> accessible later at call time, or it may be just to avoid
>recalculating
>> an expensive expression at each function call.
>>
>> The subject line idea amounts to using the same parameter list
>mechanisms,
>> but not incrementing argcount
>
>+1/2 on idea
>
>(ok, a little more complex, but that's the
>> essence) Thus:
>>     def foo(x, y=default)(z=some_expression):
>
>-1/2 on this syntax.  I would prefer ';' instead of ',' to mark end of
>run-time variable params and start of define-tine fixed params.  Have
>no idea how difficult it would be to have compiler differentiate
>between this and ';' as statement separator.
I don't think too bad, the parameter list is a special context where ';' is
a syntax error now.

>
Let's see how that looks:

    def foo(x, y=default; z=some_expression):

Not bad ;-)


>>For longer lists of initializations, it is helpful that parens allow
>putting things on multiple lines
>
>One set of parens already does this.
True

Regards,
Bengt Richter




More information about the Python-list mailing list