aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authormryouse2022-06-15 21:29:16 +0000
committermryouse2022-06-15 21:29:16 +0000
commit7b2b473976e06369310c910dc69a14450923a4d2 (patch)
tree18561f27bc71b490a092679312b77913bec83fba /libs
parentcd36d92b2a64ba48421f97c1ca3ce478d0ecd8c2 (diff)
naiive neb dicts
Diffstat (limited to 'libs')
-rw-r--r--libs/dict.neb55
1 files changed, 55 insertions, 0 deletions
diff --git a/libs/dict.neb b/libs/dict.neb
new file mode 100644
index 0000000..6547511
--- /dev/null
+++ b/libs/dict.neb
@@ -0,0 +1,55 @@
+; dicts
+(func dict () (list))
+
+(func dict? (in)
+ (def flag #true)
+ (for-each in
+ (if (not (eq? (list-length _item_) 2))
+ (redef flag #false)))
+ flag)
+
+(func has? (in key)
+ (def has #false)
+ (for-each in
+ (if (eq? (first _item_) key )
+ (redef has #true)))
+ has)
+
+(func get (d key)
+ (if (and (dict? d) (has? d key))
+ (block
+ (def val 0)
+ (for-each d
+ (if (eq? (first _item_) key)
+ (redef val (first (rest _item_)))))
+ val)
+ ; we should panic here
+ ))
+
+(func set (d key val)
+ (if (dict? d)
+ (block
+ (def out (dict))
+ (for-each d
+ (if (eq? (first _item_) key)
+ (redef out (append out (list key val)))
+ (redef out (append out _item_))))
+ (if (not (has? out key))
+ (redef out (append out (list key val))))
+ out)
+ ; we should panic here
+ ))
+
+(func keys (d) (map first d))
+
+(func drop (d key)
+ (if (dict? d)
+ (block
+ (def out (dict))
+ (for-each d
+ (if (not (eq? (first _item_) key))
+ (redef out (append out _item_))))
+ out)
+
+ ; we should panic here
+ ))