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

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Jun 12 19:23:19 EDT 2007

On 6/12/07, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> At Tue, 12 Jun 2007 17:56:00 -0500, "Robby Findler" wrote:
> > On 6/12/07, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> > > That is, `apply' still works for
> > > procedures that have optional keyword arguments. But it doesn't
> > > work for procedures that require some keyword arguments.
> >
> > What is the difference between an optional keyword argument whose
> > default is to signal an error and a required keyword argument?
> There's no difference in "kw.ss". But they would indeed be different in
> what I'm suggesting, due to things like `keyword-procedure-arity'.
> It's analogous to the difference between these two:
>   (lambda args (unless (= (length args) 1) (error "no")) ....)
>   (lambda (a) ....)
> The difference between these is visible via `procedure-arity'.
> In the keyword case, here's how the two different things would be
> written:
>  (lambda (#:y y) ....)                    ; required
>  (lambda (#:y [y (error "no y!")]) ....)  ; "optional"
> With the former, applying it to no arguments triggers an exception
> about a missing `#:y' argument, or at least "no matching case". With
> the latter, applying it to no arguments triggers an exception with "no
> y!". That's not much of a difference.
> But `keyword-procedure-arity' would say that the former requires a #:y
> argument, while it would say that the latter optionally accepts a #:y
> argument.
> In fact, maybe `procedure?' reports #f for the first and #t for the
> second. (This design point is still open, I think.)

It seems weird to not have procedure? return #t, but I can see how it
would help. We could have a keyword-procedure? that would return #t.

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


Posted on the users mailing list.