[plt-scheme] passing-on keyword arguments

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Mar 18 18:53:14 EDT 2008

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
     (lambda (kws vals . args)
       (+ (keyword-apply inner kws vals args) 5))))

I think that I know how to make it easier, allowing something like

  (define (outer args ...)
    (+ (inner args ...) 5))

to do the same, but it'll take some work to implement.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.