aboutsummaryrefslogtreecommitdiff
path: root/libs/dict.neb
blob: 7b474f465e3a006bd66532d38d1a92e0aa9a7762 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
; dicts
(func dict () (list))

(func dict? (in)
    (empty?
        (filter (lambda (x) (not (eq? x 2))) (map list-length in))))

(func has? (in key)
    (not (empty?
        (filter (lambda (x) (eq? (first x) key)) in))))

(func get (d key)
    (first (rest (first
        (filter (lambda (x) (eq? (first x) key)) d)))))

(func set (d key val)
    (if (has? d key)
        (map (lambda (x) (if (eq? key (first x)) (list (first x) val) x)) d)
        (append d (list key val))))

(func keys (d) (map first d))

(func drop (d key)
    (filter (lambda (x) (not (eq? (first x) key))) d))