aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix/utils.scm16
-rw-r--r--tests/utils.scm6
2 files changed, 22 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 34a5e6c971..2814247a68 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -48,6 +48,7 @@
compile-time-value
fcntl-flock
memoize
+ strip-keyword-arguments
default-keyword-arguments
substitute-keyword-arguments
@@ -424,6 +425,21 @@ exception if it's already taken."
(hash-set! cache args results)
(apply values results)))))))
+(define (strip-keyword-arguments keywords args)
+ "Remove all of the keyword arguments listed in KEYWORDS from ARGS."
+ (let loop ((args args)
+ (result '()))
+ (match args
+ (()
+ (reverse result))
+ (((? keyword? kw) arg . rest)
+ (loop rest
+ (if (memq kw keywords)
+ result
+ (cons* arg kw result))))
+ ((head . tail)
+ (loop tail (cons head result))))))
+
(define (default-keyword-arguments args defaults)
"Return ARGS augmented with any keyword/value from DEFAULTS for
keywords not already present in ARGS."
diff --git a/tests/utils.scm b/tests/utils.scm
index 611867ca09..a662c9a8d3 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -120,6 +120,12 @@
'(0 1 2 3)))
list))
+(test-equal "strip-keyword-arguments"
+ '(a #:b b #:c c)
+ (strip-keyword-arguments '(#:foo #:bar #:baz)
+ '(a #:foo 42 #:b b #:baz 3
+ #:c c #:bar 4)))
+
(let* ((tree (alist->vhash
'((0 2 3) (1 3 4) (2) (3 5 6) (4 6) (5) (6))
hashq))