Undo wrong fix for exec_if; fix peek-stack for false on boolean stack
This commit is contained in:
parent
0482ccccf5
commit
28da548e4c
@ -124,7 +124,7 @@
|
|||||||
:exec_if
|
:exec_if
|
||||||
^{:stacks #{:boolean :exec}}
|
^{:stacks #{:boolean :exec}}
|
||||||
(fn [state]
|
(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
|
;; 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
|
;; executed. Otherwise, it removes it. Acts as a NOOP unless there is at least
|
||||||
|
@ -35,12 +35,19 @@
|
|||||||
[state stack]
|
[state stack]
|
||||||
(empty? (get 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
|
;; Returns the top item on the stack
|
||||||
(defn peek-stack
|
(defn peek-stack
|
||||||
[state stack]
|
[state stack]
|
||||||
(if-let [top-item (first (get state stack))]
|
(if (empty? (get state stack))
|
||||||
top-item
|
:no-stack-item
|
||||||
:no-stack-item))
|
(first (get state stack))))
|
||||||
|
|
||||||
;; Returns the top n items on the stack, as a chunk. If there are less than n
|
;; 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
|
;; items on the stack, returns the entire stack
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
(defn make-instruction
|
(defn make-instruction
|
||||||
[state function arg-stacks return-stack]
|
[state function arg-stacks return-stack]
|
||||||
(let [popped-args (get-args-from-stacks state arg-stacks)]
|
(let [popped-args (get-args-from-stacks state arg-stacks)]
|
||||||
|
(println popped-args)
|
||||||
(if (= popped-args :not-enough-args)
|
(if (= popped-args :not-enough-args)
|
||||||
state
|
state
|
||||||
(let [result (apply function (:args popped-args))
|
(let [result (apply function (:args popped-args))
|
||||||
|
@ -13,21 +13,21 @@
|
|||||||
'(1 2 :integer_add) state/empty-state 1000)
|
'(1 2 :integer_add) state/empty-state 1000)
|
||||||
|
|
||||||
(interpreter/interpret-program
|
(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
|
state/empty-state
|
||||||
1000)
|
1000)
|
||||||
|
|
||||||
#_(interpreter/interpret-program
|
(interpreter/interpret-program
|
||||||
'(in1 :string_reverse 1 :string_take "?" :string_eq :exec_if
|
'(:in1 :string_reverse 1 :string_take "?" :string_eq :exec_if
|
||||||
(in1 " I am asking." :string_concat)
|
(:in1 " I am asking." :string_concat)
|
||||||
(in1 " I am saying." :string_concat))
|
(:in1 " I am saying." :string_concat))
|
||||||
(assoc state/empty-state :input {:in1 "Can you hear me?"})
|
(assoc state/empty-state :input {:in1 "Can you hear me?"})
|
||||||
1000)
|
1000)
|
||||||
|
|
||||||
#_(interpreter/interpret-program
|
(interpreter/interpret-program
|
||||||
'(in1 :string_reverse 1 :string_take "?" :string_eq :exec_if
|
'(:in1 :string_reverse 1 :string_take "?" :string_eq :exec_if
|
||||||
(in1 " I am asking." :string_concat)
|
(:in1 " I am asking." :string_concat)
|
||||||
(in1 " I am saying." :string_concat))
|
(:in1 " I am saying." :string_concat))
|
||||||
(assoc state/empty-state :input {:in1 "I can hear you."})
|
(assoc state/empty-state :input {:in1 "I can hear you."})
|
||||||
1000)
|
1000)
|
||||||
|
|
||||||
@ -61,7 +61,7 @@
|
|||||||
:step-limit 100
|
:step-limit 100
|
||||||
:parent-selection :lexicase})
|
: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
|
:error-function propeller.problems.software.number-io/error-function
|
||||||
:max-generations 500
|
:max-generations 500
|
||||||
:population-size 500
|
:population-size 500
|
||||||
|
Loading…
x
Reference in New Issue
Block a user