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.
This commit is contained in:
parent
ab1f6d4396
commit
91df21dba5
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user