From e7db1803b1aa3edb86b9e0bdfaf6f4511a405393 Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Fri, 5 Aug 2016 15:48:55 -0400 Subject: [PATCH] fixes --- src/clj/com/rpl/specter.cljx | 26 ++++++++++---------- src/clj/com/rpl/specter/macros.clj | 38 ++++++++++++++++-------------- src/clj/com/rpl/specter/navs.cljx | 7 ++---- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index c896559..e5332ed 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -2,8 +2,7 @@ #+cljs (:require-macros [com.rpl.specter.macros :refer - [pathed-collector - variable-pathed-nav + [fixed-pathed-collector fixed-pathed-nav defcollector defnav @@ -16,8 +15,7 @@ ) (:use [com.rpl.specter.protocols :only [ImplicitNav]] #+clj [com.rpl.specter.macros :only - [pathed-collector - variable-pathed-nav + [fixed-pathed-collector fixed-pathed-nav defcollector defnav @@ -41,7 +39,7 @@ (i/comp-paths* (vec apath))) (def ^{:doc "Mandate that operations that do inline path factoring and compilation - (select/transform/setval/replace-in/path/etc.) must succeed in + (select/transform/setval/replace-in/path/etc.) must succeed in factoring the path into static and dynamic portions. If not, an error will be thrown and the reasons for not being able to factor will be printed. Defaults to false, and `(must-cache-paths! false)` @@ -138,7 +136,7 @@ (defn multi-transform* "Just like `transform` but expects transform functions to be specified inline in the path using `terminal`. Error is thrown if navigation finishes - at a non-`terminal` navigator. `terminal-val` is a wrapper around `terminal` and is + at a non-`terminal` navigator. `terminal-val` is a wrapper around `terminal` and is the `multi-transform` equivalent of `setval`." [path structure] (compiled-multi-transform (i/comp-paths* path) structure)) @@ -185,7 +183,7 @@ ;; Built-in pathing and context operations (defnav - ^{:doc "Stops navigation at this point. For selection returns nothing and for + ^{:doc "Stops navigation at this point. For selection returns nothing and for transformation returns the structure unchanged"} STOP [] @@ -236,7 +234,7 @@ (n/all-transform structure next-fn))) (defnav - ^{:doc "Navigate to each value of the map. This is more efficient than + ^{:doc "Navigate to each value of the map. This is more efficient than navigating via [ALL LAST]"} MAP-VALS [] @@ -324,7 +322,7 @@ (let [to-append (next-fn [])] (n/append-all structure to-append) ))) - + (defnav ^{:doc "Navigates to the specified subset (by taking an intersection). In a transform, that subset in the original set is changed to the @@ -431,8 +429,8 @@ )) (defnav - ^{:doc "Navigate to the result of running `parse-fn` on the value. For - transforms, the transformed value then has `unparse-fn` run on + ^{:doc "Navigate to the result of running `parse-fn` on the value. For + transforms, the transformed value then has `unparse-fn` run on it to get the final value at this point."} parser [parse-fn unparse-fn] @@ -582,7 +580,7 @@ current value to the collected vals."} collect [& path] - (pathed-collector [late path] + (fixed-pathed-collector [late path] (collect-val [this structure] (compiled-select late structure) ))) @@ -592,7 +590,7 @@ current value to the collected vals."} collect-one [& path] - (pathed-collector [late path] + (fixed-pathed-collector [late path] (collect-val [this structure] (compiled-select-one late structure) ))) @@ -652,7 +650,7 @@ then-needed else-nav )))) - (let [cond-comp (i/comp-paths-internalized cond-p) + (let [cond-comp (i/comp-paths-internalized cond-p) cond-needed (i/num-needed-params cond-comp)] (richnav (+ then-needed else-needed cond-needed) (select* [this params params-idx vals structure next-fn] diff --git a/src/clj/com/rpl/specter/macros.clj b/src/clj/com/rpl/specter/macros.clj index 844204d..e97d651 100644 --- a/src/clj/com/rpl/specter/macros.clj +++ b/src/clj/com/rpl/specter/macros.clj @@ -53,10 +53,10 @@ binding-fn-syms (gensyms (count bindings)) binding-syms (map first bindings) fn-exprs (map second bindings) - binding-fn-declarations (map vector binding-fn-syms fn-exprs) - binding-declarations (map (fn [s f] `[s (f ~params-sym ~params-idx-sym)]) - binding-syms - binding-fn-syms) + binding-fn-declarations (vec (mapcat vector binding-fn-syms fn-exprs)) + binding-declarations (vec (mapcat (fn [s f] [s `(~f ~params-sym ~params-idx-sym)]) + binding-syms + binding-fn-syms)) body (op-maker binding-declarations)] `(let [~@binding-fn-declarations] ~body @@ -65,7 +65,7 @@ (defmacro rich-nav-with-bindings [num-params-code bindings & impls] (let [[[[_ s-structure-sym s-next-fn-sym] & s-body] [[_ t-structure-sym t-next-fn-sym] & t-body]] - (determine-params-impls impl1 impl2) + (apply determine-params-impls impls) params-sym (gensym "params") params-idx-sym (gensym "params-idx") ] @@ -97,7 +97,7 @@ )) ))))) -(defmacro collector-with-bindings [bindings impl] +(defmacro collector-with-bindings [num-params-code bindings impl] (let [[_ [_ structure-sym] & body] impl params-sym (gensym "params") params-idx-sym (gensym "params")] @@ -106,9 +106,11 @@ params-sym params-idx-sym (fn [binding-declarations] - `(let [cfn# (fn [params# params-idx# vals# ~structure-sym next-fn#] - (next-fn# params# params-idx# (conj vals# (do ~@body) ~structure-sym)) - )] + `(let [num-params# ~num-params-code + cfn# (fn [~params-sym ~params-idx-sym vals# ~structure-sym next-fn#] + (let [~@binding-declarations] + (next-fn# ~params-sym (+ ~params-idx-sym num-params#) (conj vals# (do ~@body) ~structure-sym)) + ))] (reify RichNavigator (~'rich-select* [this# params# params-idx# vals# structure# next-fn#] (cfn# params# params-idx# vals# structure# next-fn#)) @@ -118,7 +120,7 @@ (defn- delta-param-bindings [params] (->> params - (map (fn [i p] [p `(dnh/param-delta ~i)])) + (map-indexed (fn [i p] [p `(dnh/param-delta ~i)])) (apply concat) vec )) @@ -147,17 +149,17 @@ that needed parameters (in the order in which they were declared). " [params body] - `(let [rich-nav (collector-with-bindings ~(count params) + `(let [rich-nav# (collector-with-bindings ~(count params) ~(delta-param-bindings params) - ~impl-body + ~body )] (if ~(empty? params) - (i/no-params-rich-compiled-path rich-nav) + (i/no-params-rich-compiled-path rich-nav#) (i/->ParamsNeededPath ; (fn ~params ; (collector-with-bindings 0 ; ~impl-body)) - rich-nav + rich-nav# ~(count params)) ))) @@ -169,7 +171,7 @@ compiled-syms (vec (gensyms (count bindings))) runtime-bindings (vec (mapcat (fn [l c d] - `[~l (dfn/bound-params ~c ~d)] + `[~l (dnh/bound-params ~c ~d)] ) late-path-syms compiled-syms @@ -197,9 +199,9 @@ lean-bindings (mapcat vector late-syms compiled-syms)] `(if (zero? ~total-params-sym) (let [~@lean-bindings] - (i/lean-compiled-path (lean-nav* ~@body)) + (i/lean-compiled-path (lean-nav* ~@impls)) ) - (->ParamsNeededPath + (i/->ParamsNeededPath (rich-nav-with-bindings ~total-params-sym ~runtime-bindings ~@impls @@ -217,7 +219,7 @@ [bindings & body] (fixed-pathed-operation bindings (fn [runtime-bindings _ total-params-sym] - `(->ParamsNeededPath + `(i/->ParamsNeededPath (collector-with-bindings ~total-params-sym ~runtime-bindings ~@body diff --git a/src/clj/com/rpl/specter/navs.cljx b/src/clj/com/rpl/specter/navs.cljx index 6edaae1..f08ea1f 100644 --- a/src/clj/com/rpl/specter/navs.cljx +++ b/src/clj/com/rpl/specter/navs.cljx @@ -2,8 +2,7 @@ #+cljs (:require-macros [com.rpl.specter.macros :refer - [pathed-collector - variable-pathed-nav + [fixed-pathed-collector fixed-pathed-nav defcollector defnav @@ -169,7 +168,7 @@ #+cljs default - #+cljs + #+cljs (all-transform [structure next-fn] (let [empty-structure (empty structure)] (if (and (list? empty-structure) (not (queue? empty-structure))) @@ -469,5 +468,3 @@ (next-fn params params-idx [] structure)) (rich-transform* [this params params-idx vals structure next-fn] (next-fn params params-idx [] structure))))) - -