diff --git a/src/propeller/push/instructions/code.cljc b/src/propeller/push/instructions/code.cljc index 84c34ef..405fdc9 100755 --- a/src/propeller/push/instructions/code.cljc +++ b/src/propeller/push/instructions/code.cljc @@ -124,7 +124,7 @@ :exec_if ^{:stacks #{:boolean :exec}} (fn [state] - (make-instruction state #(if %1 %2 %3) [:boolean :exec :exec] :exec))) + (make-instruction state #(if %1 %3 %2) [:boolean :exec :exec] :exec))) ;; If the top BOOLEAN is TRUE, leaves the first item on the EXEC stack to be ;; executed. Otherwise, it removes it. Acts as a NOOP unless there is at least diff --git a/src/propeller/push/state.cljc b/src/propeller/push/state.cljc index 5026dec..3b21193 100755 --- a/src/propeller/push/state.cljc +++ b/src/propeller/push/state.cljc @@ -35,12 +35,19 @@ [state stack] (empty? (get state stack))) +;;; Returns the top item on the stack +;(defn peek-stack +; [state stack] +; (if-let [top-item (first (get state stack))] +; top-item +; :no-stack-item)) + ;; Returns the top item on the stack (defn peek-stack [state stack] - (if-let [top-item (first (get state stack))] - top-item - :no-stack-item)) + (if (empty? (get state stack)) + :no-stack-item + (first (get state stack)))) ;; Returns the top n items on the stack, as a chunk. If there are less than n ;; items on the stack, returns the entire stack diff --git a/src/propeller/push/utils/helpers.cljc b/src/propeller/push/utils/helpers.cljc index 46eb572..f9ab440 100755 --- a/src/propeller/push/utils/helpers.cljc +++ b/src/propeller/push/utils/helpers.cljc @@ -32,6 +32,7 @@ (defn make-instruction [state function arg-stacks return-stack] (let [popped-args (get-args-from-stacks state arg-stacks)] + (println popped-args) (if (= popped-args :not-enough-args) state (let [result (apply function (:args popped-args)) diff --git a/src/propeller/session.cljc b/src/propeller/session.cljc index 9317c4d..8af6922 100755 --- a/src/propeller/session.cljc +++ b/src/propeller/session.cljc @@ -13,21 +13,21 @@ '(1 2 :integer_add) state/empty-state 1000) (interpreter/interpret-program - '(3 5 :integer_eq :exec_if (1 "yes") (2 "no")) + '(3 3 :integer_eq :exec_if (1 "yes") (2 "no")) state/empty-state 1000) -#_(interpreter/interpret-program - '(in1 :string_reverse 1 :string_take "?" :string_eq :exec_if - (in1 " I am asking." :string_concat) - (in1 " I am saying." :string_concat)) +(interpreter/interpret-program + '(:in1 :string_reverse 1 :string_take "?" :string_eq :exec_if + (:in1 " I am asking." :string_concat) + (:in1 " I am saying." :string_concat)) (assoc state/empty-state :input {:in1 "Can you hear me?"}) 1000) -#_(interpreter/interpret-program - '(in1 :string_reverse 1 :string_take "?" :string_eq :exec_if - (in1 " I am asking." :string_concat) - (in1 " I am saying." :string_concat)) +(interpreter/interpret-program + '(:in1 :string_reverse 1 :string_take "?" :string_eq :exec_if + (:in1 " I am asking." :string_concat) + (:in1 " I am saying." :string_concat)) (assoc state/empty-state :input {:in1 "I can hear you."}) 1000) @@ -61,7 +61,7 @@ :step-limit 100 :parent-selection :lexicase}) -(gp/gp {:instructions propeller.problems.software.number-io/instructions +#_(gp/gp {:instructions propeller.problems.software.number-io/instructions :error-function propeller.problems.software.number-io/error-function :max-generations 500 :population-size 500