From 7aad934b9676694d08cec266e6d44c2f7d453ea2 Mon Sep 17 00:00:00 2001 From: Erik Rauer Date: Tue, 23 Mar 2021 22:42:49 -0500 Subject: [PATCH] Change `string/last` Changes `string/last` to return `:ignore-instruction` if the given string is empty --- src/propeller/push/instructions/string.cljc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/propeller/push/instructions/string.cljc b/src/propeller/push/instructions/string.cljc index 46d9811..5218ff5 100755 --- a/src/propeller/push/instructions/string.cljc +++ b/src/propeller/push/instructions/string.cljc @@ -136,12 +136,13 @@ (state/push-to-stack :exec (state/peek-stack state :exec)) (state/push-to-stack :char (first top-item)))))))) -;; Pushes the last CHAR of the top STRING +;; Pushes the last CHAR of the top STRING. +;; If the string is empty, do nothing (def-instruction :string_last ^{:stacks #{:char :string}} (fn [state] - (make-instruction state last [:string] :char))) + (make-instruction state #(if (empty? %) :ignore-instruction (last %)) [:string] :char))) ;; Pushes the length of the top STRING onto the INTEGER stack (def-instruction