From e16763df4de9e198adf48d746407d43fa5538221 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Thu, 22 Oct 2020 23:03:42 +0300 Subject: changes fix eq? for empty tables rewrite parts of the readme simplify functions rest and check-bindings --- core.fnl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'core.fnl') diff --git a/core.fnl b/core.fnl index 4890554..eba11d6 100644 --- a/core.fnl +++ b/core.fnl @@ -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)))) -- cgit v1.2.3