summaryrefslogtreecommitdiff
path: root/core.fnl
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-11-08 22:48:59 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-11-08 22:48:59 +0300
commitf9161b6b54cdaa9d773c0d0cb1b75eaf1e67318b (patch)
tree9a7228b6313be28cbfdf3d070a4af7764b269ccc /core.fnl
parent35bcc0ab3ac754e9f2ce6465c3d5c060bd5d37aa (diff)
feature(core): add hash-map function, and assoc meta to tables
Diffstat (limited to 'core.fnl')
-rw-r--r--core.fnl19
1 files changed, 15 insertions, 4 deletions
diff --git a/core.fnl b/core.fnl
index 71f2164..725add2 100644
--- a/core.fnl
+++ b/core.fnl
@@ -428,17 +428,28 @@ oppisite truth value."
(fn* core.assoc
"Associate key `k' with value `v' in `tbl'."
- ([tbl k v] (doto tbl (tset k v)))
+ ([tbl k v]
+ (setmetatable
+ (doto tbl (tset k v))
+ {:cljlib/table-type :table}))
([tbl k v & kvs]
- (assert (zero? (% (length kvs) 2)) "expected even amount key-value args")
+ (assert (= (% (length kvs) 2) 0)
+ (.. "no value supplied for key " (. kvs (length kvs))))
(tset tbl k v)
- (var [i k v] [1 nil nil])
+ (var [k v] [nil nil])
(var (i k) (next kvs))
(while i
(set (i v) (next kvs i))
(tset tbl k v)
(set (i k) (next kvs i)))
- tbl))
+ (setmetatable tbl {:cljlib/table-type :table})))
+
+(fn& core.hash-map
+ "Create associative table from keys and values"
+ [...]
+ (if (> (select :# ...) 0)
+ (assoc {} ...)
+ (setmetatable {} {:cljlib/table-type :table})))
(fn* core.get
"Get value from the table by accessing it with a `key'.