aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2016-07-30 22:57:49 +0200
committerMathieu Lirzin <mthl@gnu.org>2016-07-30 23:08:39 +0200
commite58911de37f600dffce3c562ff1d26809343d420 (patch)
tree7f180bc8a579e2301dbb50fde2a3a6f18ce5f8b7
parentac4512897c6e08f26f87d9b7ddd9120436610513 (diff)
downloadcuirass-e58911de37f600dffce3c562ff1d26809343d420.tar
cuirass-e58911de37f600dffce3c562ff1d26809343d420.tar.gz
utils: Add 'alist?' procedure.
* src/cuirass/utils.scm (alist?): New procedure. * tests/utils.scm ("alist?"): New test.
-rw-r--r--src/cuirass/utils.scm7
-rw-r--r--tests/utils.scm10
2 files changed, 17 insertions, 0 deletions
diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm
index 1667c02..56b9c6a 100644
--- a/src/cuirass/utils.scm
+++ b/src/cuirass/utils.scm
@@ -20,7 +20,9 @@
(define-module (cuirass utils)
#:use-module (ice-9 match)
+ #:use-module (srfi srfi-1)
#:export (;; Procedures
+ alist?
mkdir-p
make-user-module
;; Macros.
@@ -30,6 +32,11 @@
(define-syntax-rule (λ* formals body ...)
(lambda* formals body ...))
+(define (alist? obj)
+ "Return #t if OBJ is an alist."
+ (and (list? obj)
+ (every pair? obj)))
+
(define mkdir-p
(let ((not-slash (char-set-complement (char-set #\/))))
(λ* (dir #:optional mode)
diff --git a/tests/utils.scm b/tests/utils.scm
index 496cbee..6a14355 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -25,6 +25,16 @@
(test-begin "utils")
+(test-assert "alist?"
+ (and (alist? '())
+ (alist? '(("foo" 1 2)))
+ (alist? '(("foo" . 1)
+ ("bar" . 2)))
+ (not (alist? 3))
+ (not (alist? '(1 2 3)))
+ (not (alist? 'foo))
+ (not (alist? #:bar))))
+
(test-assert "with-directory-excursion"
(let ((old (getcwd))
(tmp (tmpnam)))