Fix string/set-char

This changes `string/set-char` to throw `:ignore-instruction` when the string is empty. Otherwise the instruction throws a Divide by Zero error.
This commit is contained in:
Erik Rauer 2021-04-01 12:04:02 -05:00
parent 27bd7b6eb6
commit e3d7963355

View File

@ -268,10 +268,12 @@
^{:stacks #{:char :integer :string}}
(fn [state]
(make-instruction state
#(let [index (mod %2 (count %3))
#(if (empty? %3)
:ignore-instruction
(let [index (mod %2 (count %3))
beginning (take index %3)
end (drop (inc index) %3)]
(apply str (concat beginning (list %1) end)))
(apply str (concat beginning (list %1) end))))
[:char :integer :string]
:string)))