This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Questions about #!key arguments


On 10/25/2011 03:27 PM, Per Bothner wrote:
We probably also want to re-think keyword arguments a bit. Given:
(lambda (a1 a2 #!key k1 k2 #!rest r) ...)
The existing "standard" is that r *includes* the keyword arguments.
I'm not sure is this is what is most useful. For a typical "builder"
function (HTML builder, Swing builder, etc) you want keyword arguments
for named properties followed by "child" expressions. You don't want
all the keyword bindings mixed up with the child parameters.

So I think we need a new delimiter - I thought of #!tail. This is like
#!rest, but it does *not* include any keyword arguments, and if there
are keyword arguments not matched by keyword parameters, then it
is an error.

Does this make sense? Suggestions for a better name than #!tail?
(Note that adding this may not happen soon.)

I haven't been using Kawa for very long, so I don't know much about its internals, but I humbly submit that there might be another option to implement #!rest like Gambit does. If #!rest appears before #!key then it contains the keywords; if #!rest appears after #!key then it does not.


Example below, full details at [1].

$ gsi
Gambit v4.6.2

(define (foo-1 #!rest r #!key (a 2) (b 3)) (values (+ a b) r))
(define (foo-2 #!key (a 2) (b 3) #!rest r) (values (+ a b) r))
(foo-1 1 2 3 4)
5
(1 2 3 4)
(foo-2 1 2 3 4)
5
(1 2 3 4)
(foo-1 a: 0 b: 42 1 2 3 4)
42
(a: 0 b: 42 1 2 3 4)
(foo-2 a: 0 b: 42 1 2 3 4)
42
(1 2 3 4)

[1] http://www.iro.umontreal.ca/~gambit/doc/gambit-c.html#Extensions-to-standard-special-forms


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]