summaryrefslogtreecommitdiff
path: root/cljlib.fnl
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-11-25 20:52:50 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-11-25 20:52:50 +0300
commit7b02ecaff4e3e884700e4ec6a0ab4db28966dca1 (patch)
tree305bb964cd05cace24d51cf24cb4d1e7b0d5e557 /cljlib.fnl
parente3f75563b8edd590e1dfce2271eaa523f19c2bde (diff)
feature(core): print empty vectors as [] in the REPL
Diffstat (limited to 'cljlib.fnl')
-rw-r--r--cljlib.fnl18
1 files changed, 11 insertions, 7 deletions
diff --git a/cljlib.fnl b/cljlib.fnl
index e7b5f31..814b3af 100644
--- a/cljlib.fnl
+++ b/cljlib.fnl
@@ -376,7 +376,14 @@ Sets additional metadata for function [`vector?`](#vector?) to work.
(assert (eq v [1 2 3 4]))
```"
[& args]
- (setmetatable args {:cljlib/type :seq}))
+ (setmetatable args {:cljlib/type :seq
+ :__fennelview (fn [t]
+ (let [res []
+ view (require :fennelview)]
+ (each [_ v (ipairs t)]
+ (insert res (view v)))
+ (.. "[" (table.concat res " ") "]")))
+ :__name "vector"}))
(fn* core.seq
"Create sequential table.
@@ -1098,12 +1105,9 @@ that would apply to that value, or `nil` if none apply and no default."
"Returns stateless `ipairs` iterator for ordered sets."
(fn []
(fn set-next [t i]
- (fn loop [t k]
- (local (k v) (next t k))
- (if v (if (= v (+ 1 i))
- (values v k)
- (loop t k))))
- (loop t))
+ (each [k v (pairs t)]
+ (if (= v (+ 1 i))
+ (lua "return v, k"))))
(values set-next Set 0)))
(fn hash-set-ipairs [Set]