[plt-scheme] keywords (a backward-incompatible change)

From: Jim Blandy (jimb at redhat.com)
Date: Sat Oct 1 19:31:02 EDT 2005

How do you distinguish a keyword passed as a value from one being used
to identify a keyword argument?

You haven't given examples of the syntax used for calling procedures
with keyword arguments.  The obvious Common-Lispy style approach would
have calls looking like this:

      (member 'a '(a b c) :equal eq?)

and member would use some sort of tail argument parsing to find its
'equal' argument, if any.

Would the following code be equivalent?

   (let ((x :equal))
     (member 'a '(a b c) x y))

If so, that's really gross.  You can't tell from looking at a call
whether it's being passed keyword arguments or not.  How do you
statically type calls like that?  And it makes using things like
'apply' treacherous: keywords appearing in the data can change the way
the argument list's elements get interpreted.

I'm not sure how to get around this.  The ideal behavior would be for
keywords to affect argument passing only when they appear directly in
the call expression.  When an argument's value is a keyword object,
that argument should be passed as a positional parameter, like
anything else.  So, the second expression above would simply call
member with four positional arguments.

Another concern: if you use variadic lambdas and case-lambdas as the
underlying implementation mechanism, then that would mean that any
function that takes keyword arguments would have an at-least-n style
arity.  You lose information.

Posted on the users mailing list.