syntax for preset locals without using dummy args with defaults

Terry Reedy tjreedy at udel.edu
Sat Jan 11 00:15:00 CET 2003


"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.

>For longer lists of initializations, it is helpful that parens allow
putting things on multiple lines

One set of parens already does this.

Terry J. Reedy






More information about the Python-list mailing list