aboutsummaryrefslogtreecommitdiff
path: root/libs/dict.neb
diff options
context:
space:
mode:
authormryouse2022-06-22 04:33:54 +0000
committermryouse2022-06-22 04:33:54 +0000
commit9a18ade08ed9eb845d2d18156ef43db5902f1f1a (patch)
tree09facb802221398641aac8f5f3981021d66c3d55 /libs/dict.neb
parent4fb8e57aa6ea23a98d24e2193065dff49f2f0b75 (diff)
dict with types (still rough)
Diffstat (limited to 'libs/dict.neb')
-rw-r--r--libs/dict.neb27
1 files changed, 18 insertions, 9 deletions
diff --git a/libs/dict.neb b/libs/dict.neb
index dd7d5ba..9dccf97 100644
--- a/libs/dict.neb
+++ b/libs/dict.neb
@@ -1,24 +1,33 @@
; dicts
-(func dict () (list))
+(func dict? (val)
+ (and
+ (list? val) ; TODO should this be automatic?
+ (or
+ (eq? 0 (list-length val))
+ (and
+ (eq? 1 (list-length val))
+ (list? (first val)))
+ (apply and (map list? val)))
+ (eq? 0 (list-length (filter (lambda (x) (not (eq? x 2))) (map list-length val))))))
+
+(type :dict :list dict?)
-(func dict? (in)
- (empty?
- (filter (lambda (x) (not (eq? x 2))) (map list-length in))))
+(func dict () (list))
-(func has? (in :list key)
+(func has? (in :dict key)
(not (empty?
(filter (lambda (x) (eq? (first x) key)) in))))
-(func get (d :list key)
+(func get (d :dict key)
(first (rest (first
(filter (lambda (x) (eq? (first x) key)) d)))))
-(func set (d :list key val)
+(func set (d :dict 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 :list) (map first d))
+(func keys (d :dict) (map first d))
-(func drop (d :list key)
+(func drop (d :dict key)
(filter (lambda (x) (not (eq? (first x) key))) d))