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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jun 12 03:08:12 EDT 2007

At Tue, 12 Jun 2007 02:55:27 -0400, Eli Barzilay wrote:
> > One drawback of this strategy is that `(lambda args (apply f args))'
> > is not an all-purpose wrapper strategy, because that only works for
> > `f' that doesn't take keyword arguments. But there would be a new
> > way to create wrappers that works for both plain and
> > keyword-accepting procedures.
> 
> Note that this one is a radical change.  It means that using keywords
> will "infect" code: using keyword-unaware code will not be possible
> with keyword aware code.  For example, SRFI code (or any portable
> Scheme code) can assume that
> 
>   (lambda args (apply f args))
> 
> is exactly equivalent to `f' -- but this will not be the case for
> keyword procedures. 

Of course, it's also not the case for numbers, lists, regexps, etc.

So probably `procedure?' should return #f for things that are like
procedures, but that require some keyword (as opposed to things that
work like procedures and accept keyword-based arguments, but all the
keyword arguments all optional). Then, the above remains true for
procedures.

Meanwhile, it's true that there's a kind of infection to the design, in
that many tools and libraries should be made to work with both
procedures and keyword-requiring things. But maybe working only for
procedures (that don't require any keywords) is a reasonable
specification for other tools and libraries.

What examples do we have, other than `trace'?

> > While we're at it, I think the form for declaring keyword-based
> > procedures more parallel to the application side --- more like SRFI-89
> > than "kw.ss".
> 
> To clarify this -- something like (imaginery syntax):
> 
>   (define (foo a b [c "Zee"] [d #:x] [e #:y "Bee"]) ...)
> 
> will define `foo' as a procedure with two required arguments, one
> optional argument, a mandatory `#:x' keyword argument (bound to `d')
> (error if it is not supplied in an application), and an optional `#:y'
> keyword.

But written like this (which is also imaginary, but specified in the
draft docs):

 (define (foo a b [c "Zee"] #:x d #:y [e "Bee"]) ...)

That is, the keyword goes before the argument without parens, just like
at at call cite. A pair of brackets groups an argument identifier with
its default-value expression, independent of whether the argument is
by-position or by-keyword.

Matthew



Posted on the users mailing list.