Implement ldict-contains? predicate.
This commit is contained in:
parent
920fab2b83
commit
a5ed5bca53
2 changed files with 23 additions and 9 deletions
13
doc/utils.md
13
doc/utils.md
|
@ -49,11 +49,18 @@ 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)
|
(ldict-empty? ld)
|
||||||
|
|
||||||
* ```d``` - a ldict instance
|
* ```ld``` - a ldict instance
|
||||||
|
|
||||||
Returns true if given dictionary contains no keys.
|
Returns ```#t``` if given dictionary contains no keys.
|
||||||
|
|
||||||
|
(ldict-contains? ld k)
|
||||||
|
|
||||||
|
* ```ld``` - a ldict instance
|
||||||
|
* ```k``` - a key compatible with given ldict
|
||||||
|
|
||||||
|
Returns ```#t``` if given ```ld``` contains given key ```k```.
|
||||||
|
|
||||||
### IO
|
### IO
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,9 @@
|
||||||
|
|
||||||
ldict-empty?
|
ldict-empty?
|
||||||
|
|
||||||
ldict-has-key?
|
ldict-contains?
|
||||||
ldict-ref
|
ldict-ref
|
||||||
|
|
||||||
ldict-remove
|
ldict-remove
|
||||||
ldict-set
|
ldict-set
|
||||||
ldict-keys
|
ldict-keys
|
||||||
|
@ -76,15 +77,21 @@
|
||||||
;; Convenience accessors
|
;; Convenience accessors
|
||||||
(define ldict-meta cadr)
|
(define ldict-meta cadr)
|
||||||
(define ldict-equality? caadr)
|
(define ldict-equality? caadr)
|
||||||
(define ldict-list cddr)
|
(define ldict-pairs cddr)
|
||||||
|
|
||||||
;; Returns true if given dictionary contains no keys
|
;; Returns true if given dictionary contains no keys
|
||||||
(define (ldict-empty? d)
|
(define (ldict-empty? ld)
|
||||||
(null? (ldict-list d)))
|
(null? (ldict-pairs ld)))
|
||||||
|
|
||||||
;; 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 (ldict-contains? ld k)
|
||||||
(if (assq k d) #t #f))
|
(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
|
;; 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
|
;; 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