summaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-01-13 17:50:17 +0100
committerLudovic Courtès <ludo@gnu.org>2016-01-13 18:18:48 +0100
commit8c986ab12034d67db836a881f57c69754d8073ae (patch)
treebf5183011119695ac549d4cfff4dc2175e659397 /guix/utils.scm
parent203795aceaabec0e0e5818e1650ad407d825d1b3 (diff)
parent7a2eed3aac1ecd0bdf293e33a234fad58f2e5f9e (diff)
downloadguix-patches-8c986ab12034d67db836a881f57c69754d8073ae.tar
guix-patches-8c986ab12034d67db836a881f57c69754d8073ae.tar.gz
Merge branch 'master' into core-updates
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm42
1 files changed, 41 insertions, 1 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 7b589e68a8..c61f105513 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013, 2014, 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
@@ -52,6 +52,7 @@
strip-keyword-arguments
default-keyword-arguments
substitute-keyword-arguments
+ ensure-keyword-arguments
<location>
location
@@ -453,6 +454,45 @@ previous value of the keyword argument."
(()
(reverse before)))))))
+(define (delkw kw lst)
+ "Remove KW and its associated value from LST, a keyword/value list such
+as '(#:foo 1 #:bar 2)."
+ (let loop ((lst lst)
+ (result '()))
+ (match lst
+ (()
+ (reverse result))
+ ((kw? value rest ...)
+ (if (eq? kw? kw)
+ (append (reverse result) rest)
+ (loop rest (cons* value kw? result)))))))
+
+(define (ensure-keyword-arguments args kw/values)
+ "Force the keywords arguments KW/VALUES in the keyword argument list ARGS.
+For instance:
+
+ (ensure-keyword-arguments '(#:foo 2) '(#:foo 2))
+ => (#:foo 2)
+
+ (ensure-keyword-arguments '(#:foo 2) '(#:bar 3))
+ => (#:foo 2 #:bar 3)
+
+ (ensure-keyword-arguments '(#:foo 2) '(#:bar 3 #:foo 42))
+ => (#:foo 42 #:bar 3)
+"
+ (let loop ((args args)
+ (kw/values kw/values)
+ (result '()))
+ (match args
+ (()
+ (append (reverse result) kw/values))
+ ((kw value rest ...)
+ (match (memq kw kw/values)
+ ((_ value . _)
+ (loop rest (delkw kw kw/values) (cons* value kw result)))
+ (#f
+ (loop rest kw/values (cons* value kw result))))))))
+
(define* (nix-system->gnu-triplet
#:optional (system (%current-system)) (vendor "unknown"))
"Return a guess of the GNU triplet corresponding to Nix system