Implement ldict-empty? predicate.

This commit is contained in:
Dominik Pantůček 2023-04-09 19:26:52 +02:00
parent 6d3d7079cf
commit 920fab2b83
2 changed files with 17 additions and 0 deletions

View file

@ -49,6 +49,12 @@ populating it with initial data.
If only one argument is given, the procedure checks whether it is a If only one argument is given, the procedure checks whether it is a
list of equality procedure and acts accordingly. list of equality procedure and acts accordingly.
(ldict-empty? d)
* ```d``` - a ldict instance
Returns true if given dictionary contains no keys.
### IO ### IO
(import util-io) (import util-io)

View file

@ -32,6 +32,8 @@
make-ldict make-ldict
ldict-empty?
ldict-has-key? ldict-has-key?
ldict-ref ldict-ref
ldict-remove ldict-remove
@ -71,6 +73,15 @@
(loop (ldict-set ld (caar pairs) (cdar pairs)) (loop (ldict-set ld (caar pairs) (cdar pairs))
(cdr 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. ;; Checks whether given dictionary d contains the key k.
(define (dict-has-key? d k) (define (dict-has-key? d k)
(if (assq k d) #t #f)) (if (assq k d) #t #f))