utils: Add 'alist?' procedure.

* src/cuirass/utils.scm (alist?): New procedure.
* tests/utils.scm ("alist?"): New test.
pull/3/head
Mathieu Lirzin 2016-07-30 22:57:49 +02:00
parent ac4512897c
commit e58911de37
No known key found for this signature in database
GPG Key ID: 0ADEE10094604D37
2 changed files with 17 additions and 0 deletions

View File

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

View File

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