Implement ldict-contains? predicate.
This commit is contained in:
parent
920fab2b83
commit
a5ed5bca53
2 changed files with 23 additions and 9 deletions
|
@ -34,8 +34,9 @@
|
|||
|
||||
ldict-empty?
|
||||
|
||||
ldict-has-key?
|
||||
ldict-contains?
|
||||
ldict-ref
|
||||
|
||||
ldict-remove
|
||||
ldict-set
|
||||
ldict-keys
|
||||
|
@ -76,15 +77,21 @@
|
|||
;; Convenience accessors
|
||||
(define ldict-meta cadr)
|
||||
(define ldict-equality? caadr)
|
||||
(define ldict-list cddr)
|
||||
(define ldict-pairs cddr)
|
||||
|
||||
;; Returns true if given dictionary contains no keys
|
||||
(define (ldict-empty? d)
|
||||
(null? (ldict-list d)))
|
||||
(define (ldict-empty? ld)
|
||||
(null? (ldict-pairs ld)))
|
||||
|
||||
;; Checks whether given dictionary d contains the key k.
|
||||
(define (dict-has-key? d k)
|
||||
(if (assq k d) #t #f))
|
||||
(define (ldict-contains? ld k)
|
||||
(let ((equality? (ldict-equality? ld)))
|
||||
(let loop ((pairs (ldict-pairs ld)))
|
||||
(if (null? pairs)
|
||||
#f
|
||||
(if (equality? (caar pairs) k)
|
||||
#t
|
||||
(loop (cdr pairs)))))))
|
||||
|
||||
;; Retrieves the value for key k from dictionary d. If third argument
|
||||
;; is provided it is used as default value in case the key does not
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue