diff --git a/doc/utils.md b/doc/utils.md index 65bf4af..5e933ad 100644 --- a/doc/utils.md +++ b/doc/utils.md @@ -49,6 +49,12 @@ populating it with initial data. If only one argument is given, the procedure checks whether it is a list of equality procedure and acts accordingly. + (ldict-empty? d) + +* ```d``` - a ldict instance + +Returns true if given dictionary contains no keys. + ### IO (import util-io) diff --git a/src/util-dict.scm b/src/util-dict.scm index 9dbf947..a904036 100644 --- a/src/util-dict.scm +++ b/src/util-dict.scm @@ -31,6 +31,8 @@ TAG-LDICT make-ldict + + ldict-empty? ldict-has-key? ldict-ref @@ -71,6 +73,15 @@ (loop (ldict-set ld (caar pairs) (cdar pairs)) (cdr pairs)))))) + ;; Convenience accessors + (define ldict-meta cadr) + (define ldict-equality? caadr) + (define ldict-list cddr) + + ;; Returns true if given dictionary contains no keys + (define (ldict-empty? d) + (null? (ldict-list d))) + ;; Checks whether given dictionary d contains the key k. (define (dict-has-key? d k) (if (assq k d) #t #f))