[plt-scheme] passing-on keyword arguments

From: Dimitris Vyzovitis (vyzo at media.mit.edu)
Date: Tue Mar 18 19:19:41 EDT 2008

On Tue, 18 Mar 2008, Eli Barzilay wrote:

> On Mar 18, Rob Hunter wrote:
> > Let me elaborate: If, for example, I had a way of passing an
> > "absent" value for a keyword argument, then I could do this with
> > functions:
> >
> > (define (inner #:x [x 10]) (* x x))
> >
> > (define (outer #:x [x ABSENT-VAL]) (+ (inner #:x x) 5))
> >
> > The semantics of ABSENT-VAL are such that if it is passed as a
> > keyword argument's val, then it as if I never set that keyword arg,
> > and thus the default value for it would be used.
>
> It's a cute idea, but it only covers one corner.  Specifically in this
> case, I think that another goal should be to avoid repeating `inner's
> interface.  There is a way to do that now, but it's not convenient:
>
>   (define outer
>     (make-keyword-procedure
>      (lambda (kws vals . args)
>        (+ (keyword-apply inner kws vals args) 5))))
>
> I think that I know how to make it easier, allowing something like
> this:
>
>   (define (outer args ...)
>     (+ (inner args ...) 5))
>
> to do the same, but it'll take some work to implement.

If you are about to embark on 'fixing' the keywords (as in make them
easier to compose), can we get a form that captures straight keywords and
an easier to use wrapper for keyword-apply?

I was thinking something like this:
(define (foo ... #:&rest kws)
  (apply/kw bar kws))
and
(apply/kw bar (cons `(#:another-kw ,val) kws))

-- vyzo



Posted on the users mailing list.