On Fri, Nov 20, 2015 at 5:28 AM, Marko Rauhamaa <ma...@pacujo.net> wrote:
> The Ackermann function really is an esoteric example, but the other
> example that has been discussed here can make practical use of the
> default-value semantics:
>
>    [ lambda x: i * x for i in range(4) ]
>
> which is salvaged with a default value:
>
>    [ lambda x, i=i: i * x for i in range(4) ]
>
> or, more hygienically:
>
>    [ (lambda i=i: lambda x: i * x)() for i in range(4) ]

Note that this last version could be rewritten as:

    [ (lambda i: lambda x: i * x)(i) for i in range(4) ]

At which point the default value semantics are no longer needed.

> One could argue that you should always use a sentinel object for default
> values. That also allows you to distinguish between omitted values and
> default values:
>
>    def asklist(caption, data, n=omitted, rows=omitted, width=omitted,
>                flags=omitted, buttons=omitted, tablist=omitted,
>                heading=omitted):
>
> but that would be rather pedantic in most circumstances.

I think that would be bad design; in general, you shouldn't *need* to
distinguish whether the value was omitted, because it should always be
possible to explicitly pass the default value.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to