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:03 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:39 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:33 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 03 Mar 2020 13:53 UTC

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

This is an interesting example. However, it's also complicated by
wrapper procedures.

The fundamental problem with wrappers is, you want to avoid having to
write things like this:

(define (wrapper)
   ...
   (cond ((and key3-supplied? key4-supplied?)
          (call/kw wrapped val1 val2 (key3 val3 key4 val4)))
         (key3-supplied?
          (call/kw wrapped val1 val2 (key3 val3)))
         (key4-supplied?
          (call/kw wrapped val1 val2 (key4 val4))
         (else
          (wrapped val1 val2))))

And instead have only one call to `wrapped`:

(define (wrapper)
   ...
   (let ((key3 (or ... default-key3))
         (key4 (or ... default-key4)))
     (call/kw wrapped val1 val2 (key3 val3 key4 val4))))

This is a lot more complicated with non-#f default values.

Also, in the presence of wrappers the distinction between which values
the programmer supplied and which they didn't supply is ambiguous. If
the programmer didn't supply a value, but the wrapper did on his behalf,
and the programmer is not familiar with the implementation of the
wrapper, did he really supply a value?

Effects like this occur in large programs, and this is what I mean by
all-#f default values being simpler to reason about and work with.