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 03 Nov 2019 10:25 UTC

> I'm thinking that instead of #f a singleton should be used instead that has
> no other purpose.

Gambit internally uses a (macro-absent-obj) for situations like this.

Its default value for keyword arguments if #f though, as is Kawa's.

Gauche's default is #<undef>, and Sagittarius' is #<unspecified>.

Based on my experience with Common Lisp, #f (nil in CL) is the best
default. Keyword args are generally used for optional arguments, and one
usually wants to do things like

(define foo
   (lambda/kw (:key this? that? other)
     (let ((really? (and this? that?))
           (other (or other 123)))
        ...)))

This is complicated a lot if we need to test for a special
(undef-object?) every time. Argument passing in wrappers is also
complicated if we need to pass (undef-object) instead of #f.

Common Lisp supports "supplied-p parameters"; boolean variables that say
whether a particular argument was given by the caller or not. I
gradually stopped using them altogether, and just used a nil default
value for everything. I also stopped using CL's custom-default-value
support for optional/kw args because the lambda-lists quickly became
unreadable and wrapper functions were a pain (you can't just pass #f for
things you don't need; you have to check each and every opt/kw arg in
the wrapped function's lambda-list to see what the default value is).
IIRC CL even allows the default values to be expressions; replicating
those expressions in wrapper functions, keeping in mind that they can be
verbose and rely on the lexical context of the wrapped function which
you don't have handy at the wrapper, really sets your hair on fire. As
you say, I say it's spinach :)

It's nice that Scheme uses (eof-object) and (eof-object?) instead of #f
for ports, since (read) can return #f. But in the case of lambda/kw the
person writing the procedure can design its arguments to work around
limitations like that. In the case of (read) you can't work around
limitations in the same way, since it has to accept arbitrary input
forms at any point in the stream.