From 920fab2b8303ccae43064fdf42c4b658bb5b0c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sun, 9 Apr 2023 19:26:52 +0200 Subject: [PATCH] Implement ldict-empty? predicate. --- doc/utils.md | 6 ++++++ src/util-dict.scm | 11 +++++++++++ 2 files changed, 17 insertions(+) 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))