In the upcoming beta 16 I have extended the DSSSL style parameter lists to better handle rest parameters when keyword parameters are used. The DSSSL syntax for the parameter list is
formal-argument-list = reqs opts rest keys
where each part can be empty. Thus the rest parameter must come before any keyword parameters, such as
(define f (lambda (a b #!rest r #!key x y) (list a b x y r))
a and b are required parameters, x and y are keyword parameters and r is the rest parameter. In DSSSL the rest parameter will contain the keyword parameters, it is not an error if other keywords are passed, and there must only be keyword/value pairs after the required parameters.
The DSSSL semantics cannot handle keywords that come before other non- keyword parameters. But this would be convenient for forms where the last parameters are a sort of body in the scope of the keyword parameters. A straightforward example is a set of functions to generate HTML. It would be nice to be able to do:
(table cellspacing: 0 cellpadding: 0 (tr (td "foo") (td "111")) (tr (td "bar") (td "222")))
The DSSSL syntax for parameter lists has been extended to allow the rest parameter to come after the keyword parameters, i.e.
formal-argument-list = reqs opts rest keys ; standard DSSSL | reqs opts keys rest ; Gambit extension
When the rest parameter comes after the keyword parameters, it will be bound to all the parameters after the keywords (i.e. it does not contain the keywords). It is an error if a keyword that is not in the parameter list is passed. Here is an example
(define g (lambda (a b #!key x y #!rest r) (list a b x y r))
(f 11 22) => (11 22 #f #f '()) (f 11 22 y: 33) => (11 22 #f 33 '(y: 33)) (f 11 22 y: 33 y: 44) => (11 22 #f 33 '(y: 33 y: 44)) (f 11 22 y: 33 z: 44) => (11 22 #f 33 '(y: 33 z: 44)) (f 11 22 y: 33 888 999) => error
(g 11 22) => (11 22 #f #f '()) (g 11 22 y: 33) => (11 22 #f 33 '()) (g 11 22 y: 33 y: 44) => (11 22 #f 33 '()) (g 11 22 888 999) => (11 22 #f #f '(888 999)) (g 11 22 y: 33 888 999) => (11 22 #f 33 '(888 999)) (g 11 22 y: 33 z: 44) => error
Moreover, in beta 16, macros can use the DSSSL and extended parameter list syntax.
Marc
Afficher les réponses par date