Fix string/nth
instruction
This changes `string/nth` to return `:ignore-instruction` when the string is empty. Otherwise it would throw an error due to dividing by zero.
This commit is contained in:
parent
8e361225ae
commit
695e08506e
@ -158,7 +158,13 @@
|
|||||||
:string_nth
|
:string_nth
|
||||||
^{:stacks #{:char :integer :string}}
|
^{:stacks #{:char :integer :string}}
|
||||||
(fn [state]
|
(fn [state]
|
||||||
(make-instruction state #(nth %2 (mod %1 (count %2))) [:integer :string] :char)))
|
(make-instruction state
|
||||||
|
#(let [str-length (count %2)]
|
||||||
|
(if (= 0 str-length)
|
||||||
|
:ignore-instruction
|
||||||
|
(nth %2 (mod %1 str-length))))
|
||||||
|
[:integer :string]
|
||||||
|
:char)))
|
||||||
|
|
||||||
;; Pushes the number of times the top CHAR occurs in the top STRING onto the
|
;; Pushes the number of times the top CHAR occurs in the top STRING onto the
|
||||||
;; INTEGER stack
|
;; INTEGER stack
|
||||||
|
Loading…
x
Reference in New Issue
Block a user