diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-11-08 22:02:54 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-11-08 22:02:54 +0300 |
| commit | 35bcc0ab3ac754e9f2ce6465c3d5c060bd5d37aa (patch) | |
| tree | 5a8c925c5a3b1ac8a5eab7bb4c516039d0dd09a7 /macros/core.fnl | |
| parent | 910bfcf768c2305a6885b0d1f491561d09ebd9ca (diff) | |
feature(core): add metadata based type inspection for tables, and empty macro
Diffstat (limited to 'macros/core.fnl')
| -rw-r--r-- | macros/core.fnl | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/macros/core.fnl b/macros/core.fnl index def2f4c..df3f8b8 100644 --- a/macros/core.fnl +++ b/macros/core.fnl @@ -66,10 +66,13 @@ `(fn [tbl#] (let [t# (type tbl#)] (if (= t# :table) - (let [(k# _#) (next tbl#)] - (if (and (= (type k#) :number) (= k# 1)) :seq - (= k# nil) :empty - :table)) + (let [meta# (getmetatable tbl#) + table-type# (and meta# (. meta# :cljlib/table-type))] + (if table-type# table-type# + (let [(k# _#) (next tbl#)] + (if (and (= (type k#) :number) (= k# 1)) :seq + (= k# nil) :empty + :table)))) :else)))) (fn seq-fn [] @@ -84,6 +87,12 @@ (insert# res# [k# v#])) (if assoc# res# tbl#)))) +(fn& core.empty [tbl] + (let [table-type (table-type tbl)] + (if (= table-type :seq) `(setmetatable {} {:cljlib/table-type :seq}) + (= table-type :table) `(setmetatable {} {:cljlib/table-type :table}) + `(setmetatable {} {:cljlib/table-type (,(table-type-fn) ,tbl)})))) + (fn& core.into [to from] (let [to-type (table-type to) from-type (table-type from)] |