[plt-scheme] keyword arguments (in v4.0, maybe)

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Jun 12 22:16:20 EDT 2007

Well, I meant something where you didn't even provide support for a
default-as-error case. I don't think the lisp default-as-nil is a good
idea, for the same reason that I think invocation of a method on a
null object in Java should be an error and I think that (car '())
should be an error, not '().

Robby

On 6/12/07, Richard Cobbe <cobbe at ccs.neu.edu> wrote:
> On Wed, Jun 13, 2007 at 07:34:50AM +0800, Matthew Flatt wrote:
> > At Tue, 12 Jun 2007 18:23:19 -0500, "Robby Findler" wrote:
> > > I guess that only having optional keyword arguments would be strange
> > > (and would lead to endless "why don't you have ..." questions on
> > > mailing lists like this one ;).
> >
> > I don't know. That might be a fine point in the design space.
>
> That's how Common Lisp does it.
>
> Given
>
>       (defun f (&key a (b 10) (c 12 c-present-p))
>         (list a b c c-present-p))
>
> then F has 3 optional keyword args, A, B, and C.  A defaults to NIL, B
> defaults to 10, and C defaults to 12.  Further, C-PRESENT-P is bound to T
> within the body of F if the caller provided an explicit value for C and to
> NIL otherwise (so if C is 12, you can tell where that 12 came from).
>
> SBCL 1.0.5 gives the following behavior (reformatted slightly for
> legibility):
>
>     * (f)
>     (NIL 10 12 NIL)
>
>     * (f :a 3 :b 4)
>     (3 4 12 NIL)
>
>     * (f :a 3 :b 4 :c 12)
>     (3 4 12 T)
>
>     * (f :a 3 :b 4 :c 15)
>     (3 4 15 T)
>
> More details at <http://www.lisp.org/HyperSpec/Body/sec_3-4-1.html>.  You
> can even override the default symbol that callers use in the argument
> list, though I didn't demonstrate that above.
>
> Richard
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.