Email list hosting service & mailing list manager

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 Marc Feeley 03 Mar 2020 13:39 UTC

> On Mar 3, 2020, at 8:19 AM, Lassi Kortela <xxxxxx@lassi.io> wrote:
>
>> I think we should make a distinction between the API thar R7RS-large will provide and the extensibility of the language by the users.
>> While for the R7RS-large API, the default value of #f will just be fine and will ease programming with the provided libraries, this does not necessarily mean that we have to prevent users from providing non-"#f" defaults in their own libraries.
>
> You can always give your own "real default value" using let:
>
> (define/kw (download url (scheme port))
>  (let* ((scheme (or scheme (url-scheme url) "http"))
>         (port   (or port (default-port scheme))))
>    ...))
>
> and indeed, people do it all the time in systems like Emacs.
>
> The only real difference is when you need to define a procedure where passing in `#f` means something distinct from an absent argument. In my opinion, it's a design mistake in the procedure if it needs to make that distinction.

Perhaps in general, but there’s at least one case where it is useful… knowing which parameters were passed to give error messages that correspond to what the programmer wrote.  For example if you have this definition

(define/kw (f str1 str2 (foo)) …)

and str1 and str2 must be strings and foo can be anything, then you want the call

(f "a-string" 'sym)

to give the error message

ERROR -- argument 2 of (f "a-string" 'sym) is not a string

not the message

ERROR -- argument 2 of (f "a-string" 'sym foo: #f) is not a string

So in the case you want to give precise error messages you want to know if the caller supplied a value for a keyword parameter or relied on the default.  The issue is the same for optional positional parameters.

Marc