Default value of keyword arguments John Cowan (03 Nov 2019 02:38 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Nov 2019 10:25 UTC)
Re: Default value of keyword arguments John Cowan (03 Nov 2019 21:24 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Nov 2019 21:44 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Nov 2019 21:52 UTC)
Re: Default value of keyword arguments John Cowan (03 Nov 2019 22:30 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Nov 2019 22:40 UTC)
Re: Default value of keyword arguments John Cowan (03 Nov 2019 23:27 UTC)
Re: Default value of keyword arguments Marc Nieper-Wißkirchen (03 Mar 2020 10:06 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Mar 2020 11:04 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Mar 2020 11:33 UTC)
Re: Default value of keyword arguments Marc Nieper-Wißkirchen (03 Mar 2020 12:50 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Mar 2020 13:19 UTC)
Re: Default value of keyword arguments Marc Feeley (03 Mar 2020 13:40 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Mar 2020 13:53 UTC)
Re: Default value of keyword arguments Marc Nieper-Wißkirchen (03 Mar 2020 14:34 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Mar 2020 15:00 UTC)
Re: Default value of keyword arguments Marc Nieper-Wißkirchen (03 Mar 2020 15:11 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Mar 2020 15:27 UTC)
Re: Default value of keyword arguments Marc Nieper-Wißkirchen (03 Mar 2020 15:51 UTC)
Re: Default value of keyword arguments Lassi Kortela (03 Mar 2020 16:06 UTC)
Re: Default value of keyword arguments John Cowan (03 Mar 2020 23:09 UTC)
Re: Default value of keyword arguments John Cowan (04 Mar 2020 17:09 UTC)
Re: Default value of keyword arguments Lassi Kortela (04 Mar 2020 17:20 UTC)
Re: Default value of keyword arguments Lassi Kortela (04 Mar 2020 17:33 UTC)
Re: Default value of keyword arguments Marc Nieper-Wißkirchen (04 Mar 2020 17:59 UTC)

Re: Default value of keyword arguments Lassi Kortela 04 Mar 2020 17:20 UTC

> There's a classic bug in Python programming where a function takes a
> list argument and mutates the argument in some way.  The programmer
> observes that [] is the most common value (empty lists are mutable in
> Python and [] is a constructor), so they set [] as the default.
>
> Unfortunately, when the default is taken and the function mutates the
> list, that mutated list becomes the default for the next call!  The safe
> strategy is to set the default to None (which is a unique object) and
> then include "if arg == None: arg = []" at the top of the function.  At
> the moment, #f is Scheme's None.

Thanks for explaining the problem. This is a textbook example of what
happens when lambda lists are allowed to be fancy :)

In the case of Lisp, and CL in particular, it's not clear whether:

- an implicit closure is created and the expressions generating default
argument values are evaluated in that closure, remembering the old
values (as in Python above).

- whether the arguments are bound in parallel as with `let`, or serially
as with `let*`, and if serially, is the evaluation order indeterminate?

It's an obscure duplication of Lisp's simple and clear `let` syntax.
`let` and #f seem too simple to be the best solution to all our default
argument woes, but I still can't think of a case where they are not.