From 91df21dba586734b1d1b4b5acfc325c6e409bcb7 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Fri, 18 Dec 2020 17:03:56 -0600 Subject: [PATCH] Fix error in `vector/_last` Similar to `vector/_first`, this didn't check for the empty vector case, so I've changed it to return `:ignore-instruction` in that case. There's a lot of duplication between `_first` and `_last`, which makes me think there's some refactoring opportunities. --- src/propeller/push/instructions/vector.cljc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/propeller/push/instructions/vector.cljc b/src/propeller/push/instructions/vector.cljc index ae2ea99..d8f695d 100755 --- a/src/propeller/push/instructions/vector.cljc +++ b/src/propeller/push/instructions/vector.cljc @@ -52,7 +52,7 @@ (make-instruction state empty? [stack] :boolean))) ;; Pushes the first item of the top element of the vector stack onto the -;; approrpiately-typed literal stack. If the vector is empty, return +;; appropriately-typed literal stack. If the vector is empty, return ;; :ignore-instruction so that nothing is changed on the stacks. (def _first ^{:stacks #{:elem}} @@ -101,7 +101,11 @@ ^{:stacks #{:elem}} (fn [stack state] (let [lit-stack (get-vector-literal-type stack)] - (make-instruction state last [stack] lit-stack)))) + (make-instruction + state + #(if (empty? %) :ignore-instruction (last %)) + [stack] + lit-stack)))) ;; Pushes the length of the top item onto the INTEGER stack (def _length