diff --git a/src/bean/functions.cljs b/src/bean/functions.cljs index fa8f4ee..03874d0 100644 --- a/src/bean/functions.cljs +++ b/src/bean/functions.cljs @@ -1,8 +1,8 @@ (ns bean.functions) (defn bean-concat [params] - (let [concated-str (reduce (fn [c {:keys [value]}] (str c value)) + (let [concated-str (reduce (fn [c {:keys [scalar]}] (str c scalar)) "" params)] - {:value concated-str + {:scalar concated-str :representation concated-str})) \ No newline at end of file diff --git a/src/bean/grid.cljs b/src/bean/grid.cljs index ad1a632..a3d0e4c 100644 --- a/src/bean/grid.cljs +++ b/src/bean/grid.cljs @@ -23,7 +23,7 @@ (defn- clear-spilled-cell [cell address] (-> cell errors/reset - (dissoc :value :spilled-from) + (dissoc :scalar :spilled-from) (update :interested-spillers disj address) (assoc :representation ""))) @@ -51,7 +51,7 @@ :spilled-from address :error (:error %2) :representation (:representation %2) - :value (:value %2)} + :scalar (:scalar %2)} (= %1 [0 0]) (merge {:matrix matrix :content (:content cell) :ast (:ast cell)}))) @@ -254,7 +254,7 @@ :ast nil ;; Evaluation results - :value nil + :scalar nil :representation nil :error nil :matrix nil diff --git a/src/bean/interpreter.cljs b/src/bean/interpreter.cljs index c3666b8..6fd6440 100644 --- a/src/bean/interpreter.cljs +++ b/src/bean/interpreter.cljs @@ -7,21 +7,21 @@ (defn- ast-result [error-or-val] (if-let [error (:error error-or-val)] (errors/stringified-error error) - {:value error-or-val + {:scalar error-or-val :representation (str error-or-val)})) (defn- fn-result [f] - {:value f + {:scalar f :representation ""}) (defn- cell->ast-result [cell] - (select-keys cell [:value :error :representation])) + (select-keys cell [:scalar :error :representation])) (defn- ast-result->cell [{:keys [error matrix] :as ast-result} cell] (merge {:content (:content cell) :ast (:ast cell) - :value (:value ast-result) + :scalar (:scalar ast-result) :representation (:representation ast-result)} (when matrix {:matrix matrix}) (when error {:error error}))) @@ -34,15 +34,15 @@ #(util/get-cell grid %) (util/addresses-matrix start-address end-address))) -(defn- apply-values +(defn- apply-results ([f ast-results] (if-let [referenced-error (first-error ast-results)] referenced-error - (ast-result (apply f (map :value ast-results))))) + (ast-result (apply f (map :scalar ast-results))))) ([f ast-results matrix] {:matrix (util/map-on-matrix - #(apply-values f (conj ast-results %)) + #(apply-results f (conj ast-results %)) matrix)})) (defn- dim [matrix] @@ -53,7 +53,7 @@ {:matrix (mapv (partial mapv (fn [l-el r-el] - (apply-values + (apply-results #(apply %1 [%2 %3]) [op l-el r-el]))) lmatrix @@ -65,18 +65,18 @@ rmatrix (:matrix right)] (cond (and lmatrix rmatrix) (matrix-op-matrix lmatrix op rmatrix) - lmatrix (apply-values #(apply %1 [%2 %3]) [op right] lmatrix) - rmatrix (apply-values #(apply %1 [%3 %2]) [op left] rmatrix) - :else (apply-values #(apply %1 [%2 %3]) [op left right])))) + lmatrix (apply-results #(apply %1 [%2 %3]) [op right] lmatrix) + rmatrix (apply-results #(apply %1 [%3 %2]) [op left] rmatrix) + :else (apply-results #(apply %1 [%2 %3]) [op left right])))) (def global-ctx - {"concat" {:value functions/bean-concat + {"concat" {:scalar functions/bean-concat :representation "f"}}) (declare apply-f) (defn eval-ast [ast {:keys [grid bindings] :as sheet}] - ; ast goes down, value or an error comes up + ; ast goes down, result or an error comes up (let [[node-type & [arg :as args]] ast eval-sub-ast #(eval-ast % sheet) eval-matrix* #(eval-matrix %1 %2 grid)] @@ -115,9 +115,9 @@ "*" operators/bean-op-*))))) (defn- apply-f [sheet f params] - (if (fn? (:value f)) - ((:value f) params) - (eval-ast (:value f) + (if (fn? (:scalar f)) + ((:scalar f) params) + (eval-ast (:scalar f) (update-in sheet [:bindings] #(merge % (into {} (map vector ["x" "y" "z"] params))))))) diff --git a/src/bean/provenance.cljs b/src/bean/provenance.cljs index 0a50ecd..437cec9 100644 --- a/src/bean/provenance.cljs +++ b/src/bean/provenance.cljs @@ -3,32 +3,32 @@ [bean.interpreter :as interpreter] [bean.errors :as errors])) -(defn- value-proof [v & args] +(defn- scalar-proof [v & args] (->> args - (concat [:value v]) + (concat [:scalar v]) (into []))) -(defn- self-evident [value] - (value-proof value :self-evident)) +(defn- self-evident [scalar] + (scalar-proof scalar :self-evident)) (defn combine-op-proof [ast-result lproof op rproof] - (let [value (:value ast-result) + (let [scalar (:scalar ast-result) matrix (:matrix ast-result) lmatrix (:matrix lproof) rmatrix (:matrix rproof)] (cond (and lmatrix rmatrix) {:matrix (util/map-on-matrix-addressed - #(value-proof (:value %2) (get-in lmatrix %1) op (get-in rmatrix %1)) + #(scalar-proof (:scalar %2) (get-in lmatrix %1) op (get-in rmatrix %1)) matrix)} lmatrix {:matrix (util/map-on-matrix-addressed - #(value-proof (get-in matrix (conj %1 :value)) %2 op rproof) + #(scalar-proof (get-in matrix (conj %1 :scalar)) %2 op rproof) lmatrix)} rmatrix {:matrix (util/map-on-matrix-addressed - #(value-proof (get-in matrix (conj %1 :value)) lproof op %2) + #(scalar-proof (get-in matrix (conj %1 :scalar)) lproof op %2) rmatrix)} - :else (value-proof value lproof op rproof)))) + :else (scalar-proof scalar lproof op rproof)))) (declare cell-proof) @@ -36,8 +36,8 @@ ;; ast goes down, proof come up (let [[node-type & [arg :as args]] ast sub-ast-proof #(ast-proof % sheet) - ast-result #(interpreter/eval-ast ast sheet) - ast-value #(:value (ast-result))] + value #(interpreter/eval-ast ast sheet) + scalar #(:scalar (value))] (case node-type :CellContents (if arg (sub-ast-proof arg) []) @@ -51,15 +51,15 @@ :Expression (if (util/is-expression? arg) (let [[left op right] args] (combine-op-proof - (ast-result) + (value) (sub-ast-proof left) (sub-ast-proof op) (sub-ast-proof right))) (sub-ast-proof arg)) :Value (sub-ast-proof arg) - :Integer (self-evident (ast-value)) - :String (self-evident (ast-value)) - :QuotedString (self-evident (ast-value)) + :Integer (self-evident (scalar)) + :String (self-evident (scalar)) + :QuotedString (self-evident (scalar)) :Operation (self-evident arg)))) (defn- spilled-cell-proof [address cell {:keys [grid] :as sheet}] @@ -69,7 +69,7 @@ {:spilled-from (:spilled-from cell) :content (:content spilled-from) :address address - :value (:value cell) + :scalar (:scalar cell) :relative-address (:relative-address cell)}] (get-in (:matrix (ast-proof (:ast spilled-from) sheet)) @@ -87,5 +87,5 @@ [:cell-ref {:address address :content (:content cell) - :value (:value cell)} + :scalar (:scalar cell)} (ast-proof (:ast cell) sheet)])))) diff --git a/src/bean/ui/sheet.cljs b/src/bean/ui/sheet.cljs index 08768a0..15e9048 100644 --- a/src/bean/ui/sheet.cljs +++ b/src/bean/ui/sheet.cljs @@ -26,7 +26,7 @@ :on-blur (fn [e] (set-mode [row col] :view) (let [input (.-textContent (.-target e))] - (set! (.-innerHTML (.-target e)) (:value cell)) + (set! (.-innerHTML (.-target e)) (:scalar cell)) (update-cell [row col] input))) :class (cs :bean-cell (when (= mode :edit) :edit-mode) diff --git a/test/bean/deps_test.cljs b/test/bean/deps_test.cljs index 121e5e6..b1f4eb9 100644 --- a/test/bean/deps_test.cljs +++ b/test/bean/deps_test.cljs @@ -13,7 +13,7 @@ (get-in grid [0 1]) {:content "=A1" :ast [:CellContents [:Expression [:CellRef "A" "1"]]] - :value 1 + :scalar 1 :representation "1"}))))) (testing "Adds an edge to the depgraph to a node that already has a dependency" @@ -25,7 +25,7 @@ (get-in grid [0 1]) {:content "=A1" :ast [:CellContents [:Expression [:CellRef "A" "1"]]] - :value 1 + :scalar 1 :representation "1"}))))) (testing "Removes a node from the depgraph if it has no edges after update" @@ -37,5 +37,5 @@ (get-in grid [0 1]) {:content "2" :ast [:CellContents [:Integer "2"]] - :value 2 + :scalar 2 :representation "2"})))))) \ No newline at end of file diff --git a/test/bean/grid_test.cljs b/test/bean/grid_test.cljs index dd50f39..0b5c73e 100644 --- a/test/bean/grid_test.cljs +++ b/test/bean/grid_test.cljs @@ -17,23 +17,23 @@ ["=A1+A2+A3+A4+10" "" ""]] evaluated-sheet (eval-sheet (new-sheet grid ""))] (is (= (util/map-on-matrix - #(select-keys % [:value :content :error :representation]) + #(select-keys % [:scalar :content :error :representation]) (:grid evaluated-sheet)) - [[{:content "1" :value 1 :representation "1"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}] - [{:content "2" :value 2 :representation "2"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}] - [{:content "=A1+A2" :value 3 :representation "3"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}] - [{:content "=A3+1" :value 4 :representation "4"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}] - [{:content "=A1+A2+A3+A4+10" :value 20 :representation "20"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}]])) + [[{:content "1" :scalar 1 :representation "1"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}] + [{:content "2" :scalar 2 :representation "2"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}] + [{:content "=A1+A2" :scalar 3 :representation "3"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}] + [{:content "=A3+1" :scalar 4 :representation "4"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}] + [{:content "=A1+A2+A3+A4+10" :scalar 20 :representation "20"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}]])) (is (= (:depgraph evaluated-sheet) {[:cell [0 0]] #{[:cell [2 0]] [:cell [4 0]]} [:cell [1 0]] #{[:cell [2 0]] [:cell [4 0]]} @@ -46,20 +46,20 @@ ["=A1+A2" "=B2" ""] ["=A3+1" "" ""]]] (is (= (util/map-on-matrix - #(select-keys % [:value :content :error :representation]) + #(select-keys % [:scalar :content :error :representation]) (:grid (eval-sheet (new-sheet grid "")))) - [[{:content "=1" :value 1 :representation "1"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}] - [{:content "ABC" :value "ABC" :representation "ABC"} - {:content "=A1000" :value nil :error "Invalid address [999 0]" :representation "Invalid address [999 0]"} - {:content "" :value nil :representation ""}] - [{:content "=A1+A2" :value nil :error "+ only works for Integers" :representation "+ only works for Integers"} - {:content "=B2" :value nil :error "Invalid address [999 0]" :representation "Invalid address [999 0]"} - {:content "" :value nil :representation ""}] - [{:content "=A3+1" :value nil :error "+ only works for Integers" :representation "+ only works for Integers"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}]])))) + [[{:content "=1" :scalar 1 :representation "1"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}] + [{:content "ABC" :scalar "ABC" :representation "ABC"} + {:content "=A1000" :scalar nil :error "Invalid address [999 0]" :representation "Invalid address [999 0]"} + {:content "" :scalar nil :representation ""}] + [{:content "=A1+A2" :scalar nil :error "+ only works for Integers" :representation "+ only works for Integers"} + {:content "=B2" :scalar nil :error "Invalid address [999 0]" :representation "Invalid address [999 0]"} + {:content "" :scalar nil :representation ""}] + [{:content "=A3+1" :scalar nil :error "+ only works for Integers" :representation "+ only works for Integers"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}]])))) (testing "Errors are not operated upon further" (let [grid [["=A1000+1" "=A1+100" ""]]] @@ -87,15 +87,15 @@ matrix (get-in evaluated-sheet [:grid 1 1 :matrix])] (is (= matrix [[{:content "1" :ast [:CellContents [:Integer "1"]] - :value 1 + :scalar 1 :representation "1"}] [{:content "2" :ast [:CellContents [:Integer "2"]] - :value 2 + :scalar 2 :representation "2"}]])) - (is (= (get-in evaluated-sheet [:grid 1 1 :value]) 1)) + (is (= (get-in evaluated-sheet [:grid 1 1 :scalar]) 1)) (is (= (get-in evaluated-sheet [:grid 1 1 :spilled-into]) #{[1 1] [2 1]})) - (is (= (get-in evaluated-sheet [:grid 2 1 :value]) 2)))) + (is (= (get-in evaluated-sheet [:grid 2 1 :scalar]) 2)))) (testing "Matrix spill errors if a cell has some content" (let [grid [["1" ""] @@ -104,18 +104,18 @@ evaluated-sheet (eval-sheet (new-sheet grid ""))] (is (get-in evaluated-sheet [:grid 1 1 :matrix])) (is (= (get-in evaluated-sheet [:grid 1 1 :error]) "Spill error")) - (is (= (get-in evaluated-sheet [:grid 2 1 :value]) "A string")))) + (is (= (get-in evaluated-sheet [:grid 2 1 :scalar]) "A string")))) (testing "Matrix spill errors if there's a conflict" (let [grid [["1" "3"] ["2" "=A1:A2"] ["=A1:B1" ""]] evaluated-sheet (eval-sheet (new-sheet grid ""))] - (is (= (get-in evaluated-sheet [:grid 1 1 :value]) 1)) - (is (= (get-in evaluated-sheet [:grid 2 1 :value]) 2)) + (is (= (get-in evaluated-sheet [:grid 1 1 :scalar]) 1)) + (is (= (get-in evaluated-sheet [:grid 2 1 :scalar]) 2)) (is (= (get-in evaluated-sheet [:grid 2 0 :error]) "Spill error")) (is (= (get-in evaluated-sheet [:grid 2 0 :representation]) "Spill error")) - (is (= (get-in evaluated-sheet [:grid 2 0 :value]) nil)) + (is (= (get-in evaluated-sheet [:grid 2 0 :scalar]) nil)) (is (= (util/map-on-matrix :representation (:grid evaluated-sheet)) [["1" "3"] ["2" "1"] @@ -129,57 +129,57 @@ ["" "" ""] ["" "" ""]] "")))] - (is (= (get-in grid [2 1 :value]) 2)) - (is (= (get-in grid [3 0 :value]) 2)) - (is (= (get-in grid [3 1 :value]) 3)) - (is (= (get-in grid [4 1 :value]) 2)))) + (is (= (get-in grid [2 1 :scalar]) 2)) + (is (= (get-in grid [3 0 :scalar]) 2)) + (is (= (get-in grid [3 1 :scalar]) 3)) + (is (= (get-in grid [4 1 :scalar]) 2)))) (testing "Function invocation" (is (= (util/map-on-matrix - #(select-keys % [:value :content :error :representation]) + #(select-keys % [:scalar :content :error :representation]) (:grid (eval-sheet (new-sheet [["1" "=concat(\"hello \" A1 A2)" ""] ["2" "" ""] ["=A1+A2" "" ""] ["=A3+1" "" ""] ["=A1+A2+A3+A4+10" "" ""]] "")))) - [[{:content "1" :value 1 :representation "1"} - {:content "=concat(\"hello \" A1 A2)" :value "hello 12" :representation "hello 12"} - {:content "" :value nil :representation ""}] - [{:content "2" :value 2 :representation "2"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}] - [{:content "=A1+A2" :value 3 :representation "3"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}] - [{:content "=A3+1" :value 4 :representation "4"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}] - [{:content "=A1+A2+A3+A4+10" :value 20 :representation "20"} - {:content "" :value nil :representation ""} - {:content "" :value nil :representation ""}]]))) + [[{:content "1" :scalar 1 :representation "1"} + {:content "=concat(\"hello \" A1 A2)" :scalar "hello 12" :representation "hello 12"} + {:content "" :scalar nil :representation ""}] + [{:content "2" :scalar 2 :representation "2"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}] + [{:content "=A1+A2" :scalar 3 :representation "3"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}] + [{:content "=A3+1" :scalar 4 :representation "4"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}] + [{:content "=A1+A2+A3+A4+10" :scalar 20 :representation "20"} + {:content "" :scalar nil :representation ""} + {:content "" :scalar nil :representation ""}]]))) (testing "Inlined function invocation" (is (= (util/map-on-matrix - #(select-keys % [:value :content :error :representation]) + #(select-keys % [:scalar :content :error :representation]) (:grid (eval-sheet (new-sheet [["1" "={x+y+z}(9 A1 A2)"] ["2" ""]] "")))) - [[{:content "1" :value 1 :representation "1"} - {:content "={x+y+z}(9 A1 A2)" :value 12 :representation "12"}] - [{:content "2" :value 2 :representation "2"} - {:content "" :value nil :representation ""}]])))) + [[{:content "1" :scalar 1 :representation "1"} + {:content "={x+y+z}(9 A1 A2)" :scalar 12 :representation "12"}] + [{:content "2" :scalar 2 :representation "2"} + {:content "" :scalar nil :representation ""}]])))) (deftest incremental-evaluate-grid (testing "Basic incremental evaluation given a pre-evaluated grid and a depgraph" (let [sheet (eval-sheet (new-sheet [["10" "=A1" "=A1+B1" "100" "=C1" "=A1"]] "")) {evaluated-grid :grid depgraph :depgraph} (eval-cell [0 1] sheet "=A1+D1")] - (is (= 10 (:value (util/get-cell evaluated-grid [0 0])))) - (is (= 110 (:value (util/get-cell evaluated-grid [0 1])))) - (is (= 120 (:value (util/get-cell evaluated-grid [0 2])))) - (is (= 100 (:value (util/get-cell evaluated-grid [0 3])))) - (is (= 120 (:value (util/get-cell evaluated-grid [0 4])))) + (is (= 10 (:scalar (util/get-cell evaluated-grid [0 0])))) + (is (= 110 (:scalar (util/get-cell evaluated-grid [0 1])))) + (is (= 120 (:scalar (util/get-cell evaluated-grid [0 2])))) + (is (= 100 (:scalar (util/get-cell evaluated-grid [0 3])))) + (is (= 120 (:scalar (util/get-cell evaluated-grid [0 4])))) (is (= depgraph {[:cell [0 0]] #{[:cell [0 1]] [:cell [0 2]] [:cell [0 5]]} [:cell [0 1]] #{[:cell [0 2]]} @@ -294,7 +294,7 @@ (as-> (new-sheet [["1" "2"]] "addaone:4+A1") sheet (eval-sheet sheet) (eval-cell [0 0] sheet "6") - (get-in sheet [:bindings "addaone" :value]))))) + (get-in sheet [:bindings "addaone" :scalar]))))) (testing "Depgraph is updated when a named reference's dependencies change" (is (= {[:cell [0 1]] #{[:named "addaone"]}} diff --git a/test/bean/interpreter_test.cljs b/test/bean/interpreter_test.cljs index f13bdf7..0b63075 100644 --- a/test/bean/interpreter_test.cljs +++ b/test/bean/interpreter_test.cljs @@ -5,35 +5,35 @@ (deftest apply-op-test (testing "Applies an op to a matrix and a scalar" - (is (= (apply-op {:value operators/bean-op-+} {:value 1} - {:matrix [[{:value 1} - {:value 2} - {:value 1}]]}) + (is (= (apply-op {:scalar operators/bean-op-+} {:scalar 1} + {:matrix [[{:scalar 1} + {:scalar 2} + {:scalar 1}]]}) {:matrix - [[{:value 2 :representation "2"} - {:value 3 :representation "3"} - {:value 2 :representation "2"}]]}))) + [[{:scalar 2 :representation "2"} + {:scalar 3 :representation "3"} + {:scalar 2 :representation "2"}]]}))) (testing "Applies an op to a scalar and a matrix" - (is (= (apply-op {:value operators/bean-op-+} - {:matrix [[{:value 1} - {:value 2} - {:value 1}]]} - {:value 1}) + (is (= (apply-op {:scalar operators/bean-op-+} + {:matrix [[{:scalar 1} + {:scalar 2} + {:scalar 1}]]} + {:scalar 1}) {:matrix - [[{:value 2 :representation "2"} - {:value 3 :representation "3"} - {:value 2 :representation "2"}]]}))) + [[{:scalar 2 :representation "2"} + {:scalar 3 :representation "3"} + {:scalar 2 :representation "2"}]]}))) (testing "Applies an op to a scalar and a matrix" - (is (= (apply-op {:value operators/bean-op-+} - {:matrix [[{:value 1} - {:value 2} - {:value 1}]]} - {:matrix [[{:value 1} - {:value 2} - {:value 1}]]}) + (is (= (apply-op {:scalar operators/bean-op-+} + {:matrix [[{:scalar 1} + {:scalar 2} + {:scalar 1}]]} + {:matrix [[{:scalar 1} + {:scalar 2} + {:scalar 1}]]}) {:matrix - [[{:value 2 :representation "2"} - {:value 4 :representation "4"} - {:value 2 :representation "2"}]]})))) + [[{:scalar 2 :representation "2"} + {:scalar 4 :representation "4"} + {:scalar 2 :representation "2"}]]})))) diff --git a/test/bean/provenance_test.cljs b/test/bean/provenance_test.cljs index a6ecf6b..8c21b3c 100644 --- a/test/bean/provenance_test.cljs +++ b/test/bean/provenance_test.cljs @@ -9,75 +9,75 @@ (grid/new-sheet [["" "1" "=1+2" "=1+2+3"]] ""))] (is (= (provenance/cell-proof [0 0] evaled-grid) [:cell-ref - {:address [0 0] :value nil :content ""} + {:address [0 0] :scalar nil :content ""} []])) (is (= (provenance/cell-proof [0 1] evaled-grid) [:cell-ref - {:address [0 1] :value 1 :content "1"} - [:value 1 :self-evident]])) + {:address [0 1] :scalar 1 :content "1"} + [:scalar 1 :self-evident]])) (is (= (provenance/cell-proof [0 2] evaled-grid) [:cell-ref - {:address [0 2] :value 3 :content "=1+2"} - [:value 3 - [:value 1 :self-evident] - [:value "+" :self-evident] - [:value 2 :self-evident]]])) + {:address [0 2] :scalar 3 :content "=1+2"} + [:scalar 3 + [:scalar 1 :self-evident] + [:scalar "+" :self-evident] + [:scalar 2 :self-evident]]])) (is (= (provenance/cell-proof [0 3] evaled-grid) [:cell-ref - {:address [0 3] :value 6 :content "=1+2+3"} - [:value 6 - [:value 1 :self-evident] - [:value "+" :self-evident] - [:value 5 - [:value 2 :self-evident] - [:value "+" :self-evident] - [:value 3 :self-evident]]]])))) + {:address [0 3] :scalar 6 :content "=1+2+3"} + [:scalar 6 + [:scalar 1 :self-evident] + [:scalar "+" :self-evident] + [:scalar 5 + [:scalar 2 :self-evident] + [:scalar "+" :self-evident] + [:scalar 3 :self-evident]]]])))) (testing "Provenance for cell references" (let [evaled-grid (grid/eval-sheet (grid/new-sheet [["1" "=A1" "=B1"]] ""))] (is (= (provenance/cell-proof [0 1] evaled-grid) [:cell-ref - {:address [0 1] :content "=A1" :value 1} + {:address [0 1] :content "=A1" :scalar 1} [:cell-ref - {:address [0 0] :content "1" :value 1} - [:value 1 :self-evident]]])) + {:address [0 0] :content "1" :scalar 1} + [:scalar 1 :self-evident]]])) (is (= (provenance/cell-proof [0 2] evaled-grid) [:cell-ref - {:address [0 2] :content "=B1" :value 1} + {:address [0 2] :content "=B1" :scalar 1} [:cell-ref - {:address [0 1] :content "=A1" :value 1} + {:address [0 1] :content "=A1" :scalar 1} [:cell-ref - {:address [0 0] :content "1" :value 1} - [:value 1 :self-evident]]]])))) + {:address [0 0] :content "1" :scalar 1} + [:scalar 1 :self-evident]]]])))) (testing "Provenance for multiple cell references" (let [evaled-grid (grid/eval-sheet (grid/new-sheet [["1" "2" "=A1+B1"] ["=C1" "" ""]] ""))] (is (= (provenance/cell-proof [0 2] evaled-grid) [:cell-ref - {:address [0 2] :content "=A1+B1" :value 3} - [:value 3 + {:address [0 2] :content "=A1+B1" :scalar 3} + [:scalar 3 [:cell-ref - {:address [0 0] :content "1" :value 1} - [:value 1 :self-evident]] - [:value "+" :self-evident] + {:address [0 0] :content "1" :scalar 1} + [:scalar 1 :self-evident]] + [:scalar "+" :self-evident] [:cell-ref - {:address [0 1] :content "2" :value 2} - [:value 2 :self-evident]]]])) + {:address [0 1] :content "2" :scalar 2} + [:scalar 2 :self-evident]]]])) (is (= (provenance/cell-proof [1 0] evaled-grid) [:cell-ref - {:address [1 0] :content "=C1" :value 3} + {:address [1 0] :content "=C1" :scalar 3} [:cell-ref - {:address [0 2] :content "=A1+B1" :value 3} - [:value 3 + {:address [0 2] :content "=A1+B1" :scalar 3} + [:scalar 3 [:cell-ref - {:address [0 0] :content "1" :value 1} - [:value 1 :self-evident]] - [:value "+" :self-evident] + {:address [0 0] :content "1" :scalar 1} + [:scalar 1 :self-evident]] + [:scalar "+" :self-evident] [:cell-ref - {:address [0 1] :content "2" :value 2} - [:value 2 :self-evident]]]]])))) + {:address [0 1] :content "2" :scalar 2} + [:scalar 2 :self-evident]]]]])))) (testing "Provenance of spilled cells" (let [evaled-grid (grid/eval-sheet @@ -87,21 +87,21 @@ {:spilled-from [0 1] :content "=A1:A2" :address [0 1] - :value 1 + :scalar 1 :relative-address [0 0]} [:cell-ref - {:address [0 0] :content "1" :value 1} - [:value 1 :self-evident]]])) + {:address [0 0] :content "1" :scalar 1} + [:scalar 1 :self-evident]]])) (is (= (provenance/cell-proof [1 1] evaled-grid) [:spill {:spilled-from [0 1] :content "=A1:A2" :address [1 1] - :value 2 + :scalar 2 :relative-address [1 0]} [:cell-ref - {:address [1 0] :content "2" :value 2} - [:value 2 :self-evident]]])))) + {:address [1 0] :content "2" :scalar 2} + [:scalar 2 :self-evident]]])))) (testing "Provenance for matrix opertions" (let [evaled-grid (grid/eval-sheet @@ -113,18 +113,18 @@ {:spilled-from [0 1] :content "=A1:A2+C1:C2" :address [1 1] - :value 3 + :scalar 3 :relative-address [1 0]} - [:value 3 + [:scalar 3 [:cell-ref - {:address [1 0] :content "2" :value 2} - [:value 2 :self-evident]] - [:value "+" :self-evident] + {:address [1 0] :content "2" :scalar 2} + [:scalar 2 :self-evident]] + [:scalar "+" :self-evident] [:cell-ref - {:address [1 2] :content "=A1" :value 1} + {:address [1 2] :content "=A1" :scalar 1} [:cell-ref - {:address [0 0] :content "1" :value 1} - [:value 1 :self-evident]]]]])))) + {:address [0 0] :content "1" :scalar 1} + [:scalar 1 :self-evident]]]]])))) (testing "Provenance for matrix-scalar operations" (let [evaled-grid (grid/eval-sheet (grid/new-sheet [["1" "=A1:A2+1"] @@ -135,14 +135,14 @@ {:spilled-from [0 1] :content "=A1:A2+1" :address [1 1] - :value 3 + :scalar 3 :relative-address [1 0]} - [:value 3 + [:scalar 3 [:cell-ref - {:address [1 0] :content "2" :value 2} - [:value 2 :self-evident]] - [:value "+" :self-evident] - [:value 1 :self-evident]]]))) + {:address [1 0] :content "2" :scalar 2} + [:scalar 2 :self-evident]] + [:scalar "+" :self-evident] + [:scalar 1 :self-evident]]]))) (let [evaled-grid (grid/eval-sheet (grid/new-sheet [["1" "=A1:A2+C1:C2+D1:D2+1" "3" "0"] @@ -153,21 +153,21 @@ {:spilled-from [0 1] :content "=A1:A2+C1:C2+D1:D2+1" :address [1 1] - :value 7 + :scalar 7 :relative-address [1 0]} - [:value 7 + [:scalar 7 [:cell-ref - {:address [1 0] :content "2" :value 2} - [:value 2 :self-evident]] - [:value "+" :self-evident] - [:value 5 + {:address [1 0] :content "2" :scalar 2} + [:scalar 2 :self-evident]] + [:scalar "+" :self-evident] + [:scalar 5 [:cell-ref - {:address [1 2] :content "4" :value 4} - [:value 4 :self-evident]] - [:value "+" :self-evident] - [:value 1 + {:address [1 2] :content "4" :scalar 4} + [:scalar 4 :self-evident]] + [:scalar "+" :self-evident] + [:scalar 1 [:cell-ref - {:address [1 3] :content "0" :value 0} - [:value 0 :self-evident]] - [:value "+" :self-evident] - [:value 1 :self-evident]]]]]))))) + {:address [1 3] :content "0" :scalar 0} + [:scalar 0 :self-evident]] + [:scalar "+" :self-evident] + [:scalar 1 :self-evident]]]]])))))