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)))