diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-10-22 23:03:42 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-10-22 23:03:42 +0300 |
| commit | e16763df4de9e198adf48d746407d43fa5538221 (patch) | |
| tree | 3015c6d25357f88fd0e4493de2e6d597136d96ad /core.fnl | |
| parent | 54a83a9f0506804a597875f3eaf4de874bf6762f (diff) | |
changes
fix eq? for empty tables
rewrite parts of the readme
simplify functions rest and check-bindings
Diffstat (limited to 'core.fnl')
| -rw-r--r-- | core.fnl | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -3,10 +3,11 @@ (import-macros {: fn*} :macros.fn) (fn seq [tbl] - "Return sequential table. + "Create sequential table. Transforms original table to sequential table of key value pairs -stored as sequential tables in linear time. If original table is -sequential table, leaves it unchanged." +stored as sequential tables in linear time. If `tbl' is an +associative table, returns `[[key1 value1] ... [keyN valueN]]' table. +If `tbl' is sequential table, leaves it unchanged." (var assoc? false) (let [res []] (each [k v (pairs tbl)] @@ -23,8 +24,7 @@ sequential table, leaves it unchanged." (fn rest [itbl] "Returns table of all elements of indexed table but the first one." - (let [[_ & xs] (seq itbl)] - xs)) + [(_unpack itbl 2)]) (fn* conj @@ -175,8 +175,8 @@ sorting tables first." ([x] true) ([x y] (if (and (= (type x) "table") (= (type y) "table")) - (and (reduce #(and $1 $2) (mapv (fn [[k v]] (eq? (. y k) v)) (kvseq x))) - (reduce #(and $1 $2) (mapv (fn [[k v]] (eq? (. x k) v)) (kvseq y)))) + (and (reduce #(and $1 $2) true (mapv (fn [[k v]] (eq? (. y k) v)) (kvseq x))) + (reduce #(and $1 $2) true (mapv (fn [[k v]] (eq? (. x k) v)) (kvseq y)))) (= x y))) ([x y & xs] (reduce #(and $1 $2) (eq? x y) (mapv #(eq? x $) xs)))) |