diff options
author | Eric Bavier <bavier@member.fsf.org> | 2016-09-20 15:41:31 -0500 |
---|---|---|
committer | Eric Bavier <bavier@member.fsf.org> | 2016-10-07 07:42:05 -0500 |
commit | b8b129ebd8d017c957094f3d977a1c452d7d450f (patch) | |
tree | 5fa5860e6e7725c1cffae5da6b282ef82bb09e07 /guix | |
parent | 347df60158a11abbc9b84ac36cd113362d7e09e0 (diff) |
utils: Support defaults in substitute-keyword-arguments.
* guix/utils.scm (collect-default-args, expand-default-args): New
syntax.
(substitute-keyword-arguments): Allow default value declarations.
* tests/utils.scm (substitute-keyword-arguments): New test.
Diffstat (limited to 'guix')
-rw-r--r-- | guix/utils.scm | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/guix/utils.scm b/guix/utils.scm index ded31142aa..decadf64a6 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -375,13 +375,24 @@ keywords not already present in ARGS." (() args)))) +(define-syntax collect-default-args + (syntax-rules () + ((_) + '()) + ((_ (_ _) rest ...) + (collect-default-args rest ...)) + ((_ (kw _ dflt) rest ...) + (cons* kw dflt (collect-default-args rest ...))))) + (define-syntax substitute-keyword-arguments (syntax-rules () "Return a new list of arguments where the value for keyword arg KW is -replaced by EXP. EXP is evaluated in a context where VAR is boud to the -previous value of the keyword argument." - ((_ original-args ((kw var) exp) ...) - (let loop ((args original-args) +replaced by EXP. EXP is evaluated in a context where VAR is bound to the +previous value of the keyword argument, or DFLT if given." + ((_ original-args ((kw var dflt ...) exp) ...) + (let loop ((args (default-keyword-arguments + original-args + (collect-default-args (kw var dflt ...) ...))) (before '())) (match args ((kw var rest (... ...)) |