Default parameters

Bengt Richter bokr at oz.net
Sun Dec 21 14:01:45 EST 2003


On Sun, 21 Dec 2003 12:02:04 -0500, "Terry Reedy" <tjreedy at udel.edu> wrote:

>
>"Bengt Richter" <bokr at oz.net> wrote in message
>news:bs1lov$3vu$0 at 216.39.172.122...
>> That's useful, but IMO not the optimal syntax,
>because cache here is really not
>> being used as a parameter. That's why I would
>like a way to bind locals similarly
>> without being part of the calling signature.
>E.g.,
>>
>> def _tento(n)(
>>     # preset bindings evaluated here at def-time
>>     cache={}
>> ):
>>     try:
>>         return cache[n]
>>     except KeyError:
>>         answer = cache[n] = 10L ** n
>>         return answer
>
>I have also thought of using a ';' as in
>def _tento(n; cache = {}):
>  [etc]
>
>to indicate a def-time initialized  non-parameter.
>
That's nice and concise. I wonder how best to use that for generators. I.e.,
the current parameter list of a generator is effectively gen(; current_stuff): ...
where the first part could be interpreted as optional parameters of .next().

Regards,
Bengt Richter




More information about the Python-list mailing list