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

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Jun 13 07:33:11 EDT 2007

On Jun 13, Robby Findler wrote:
> On 6/12/07, Eli Barzilay <eli at barzilay.org> wrote:
> > On Jun 12, Robby Findler wrote:
> > > Here's another question (which I think your macro expansion
> > > message may have answered implicitly, I'm not sure): what
> > > happens when I do something like this:
> > >
> > >   (lambda args (printf "~s\n" args) (apply f args))
> > >
> > > [...]
> >
> > You won't be able to see them -- and the problem that I'm talking
> > about is that you won't be able to accept them.  This procedure
> > will simply barf if given keyword arguments.  (At least IIUC, and
> > I think I do...)  The bottom line is that this procedure is
> > sort-of like a traced `f' except that it does not accept keyword
> > arguments at all.  (More in a separate message.)
> >
> You and Matthew seem to be in direct contradiction on this point.

If you remember, the problem started with

  f == (lambda xs (apply f xs))

not being true for keyworded arguments.  The rest argument does not
have the keyword information -- unlike the current situation with

As Matthew mentioned later, you will need an explicit
`make-keyword-procedure' to access the keywords -- without that, you
will not be able to see them, and because you have a non-keyword
procedure, calling it with keywords is an arity error.  As Matthew

|(define (trace-wrap f)
|   (make-keyword-procedure
|    (lambda (kw-args . rest)
|      (printf "Called with ~s ~s\n" kw-args rest)
|      (keyword-apply f kw-args rest))))
| > ((trace-wrap greet) "John" #:hi "Howdy")
| Called with ((#:hi . "Howdy")) ("John")
| "Howdy, John Smith"

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

Posted on the users mailing list.