Created
February 16, 2018 17:43
-
-
Save Vaguery/088965401765bb39df7c7614308fe87c to your computer and use it in GitHub Desktop.
Trace of an evolved FizzBuzz program in Push
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clojush.core=> (run-push my-program start-state true) | |
State after 0 steps: | |
;; program is pushed onto :exec; input is set to 15 | |
:exec = ((exec_stackdepth integer_mod exec_s string_swap in1 integer_mult exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false)) | |
:integer = nil | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 1 steps (last step: (...)): | |
;; unwrapped code block (the whole program) | |
:exec = (exec_stackdepth integer_mod exec_s string_swap in1 integer_mult exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = nil | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 2 steps (last step: exec_stackdepth): | |
;; pushes the count of individual items on the :exec stack onto :integer | |
:exec = (integer_mod exec_s string_swap in1 integer_mult exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 3 steps (last step: integer_mod): | |
;; missing arguments; nothing happens | |
:exec = (exec_s string_swap in1 integer_mult exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 4 steps (last step: exec_s): | |
;; pops top three things (A, B, C) from :exec; pushes "A C (B C)" | |
:exec = (string_swap integer_mult (in1 integer_mult) exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 5 steps (last step: string_swap): | |
;; missing arguments; nothing happens | |
:exec = (integer_mult (in1 integer_mult) exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 6 steps (last step: integer_mult): | |
;; missing arguments; nothing happens | |
:exec = ((in1 integer_mult) exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 7 steps (last step: (...)): | |
;; unwrapped code block | |
:exec = (in1 integer_mult exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 8 steps (last step: in1): | |
;; look up input value (Clojush pushes it directly to :integer) | |
:exec = (integer_mult exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15 15) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 9 steps (last step: integer_mult): | |
;; multiply the top two :integer items | |
:exec = (exec_stackdepth integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (225) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 10 steps (last step: exec_stackdepth): | |
;; count how many items on :exec, and push that number to :integer | |
:exec = (integer_mod "fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (9 225) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 11 steps (last step: integer_mod): | |
;; push (mod 225 9) to :integer | |
:exec = ("fizz" exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (0) | |
:boolean = nil | |
:string = nil | |
:input = (15) | |
State after 12 steps (last step: fizz): | |
;; string literal "fizz" | |
:exec = (exec_do*range (string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (0) | |
:boolean = nil | |
:string = ("fizz") | |
:input = (15) | |
State after 13 steps (last step: exec_do*range): | |
;; this _would_ loop, but its numeric arguments are missing | |
:exec = ((string_parse_to_chars string_rest "fizz" string_shove) in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (0) | |
:boolean = nil | |
:string = ("fizz") | |
:input = (15) | |
State after 14 steps (last step: (...)): | |
;; unwrap code block | |
:exec = (string_parse_to_chars string_rest "fizz" string_shove in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (0) | |
:boolean = nil | |
:string = ("fizz") | |
:input = (15) | |
State after 15 steps (last step: string_parse_to_chars): | |
;; break up top :string item to individual 1-character strings | |
:exec = (string_rest "fizz" string_shove in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (0) | |
:boolean = nil | |
:string = ("f" "i" "z" "z") | |
:input = (15) | |
State after 16 steps (last step: string_rest): | |
;; remove first character from top :string | |
:exec = ("fizz" string_shove in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (0) | |
:boolean = nil | |
:string = ("" "i" "z" "z") | |
:input = (15) | |
State after 17 steps (last step: fizz): | |
;; string literal "fizz" | |
:exec = (string_shove in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (0) | |
:boolean = nil | |
:string = ("fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 18 steps (last step: string_shove): | |
;; this "moves" the top :string item to position 0 (the top :integer item), not moving it | |
:exec = (in1 boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = () | |
:boolean = nil | |
:string = ("fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 19 steps (last step: in1): | |
;; input value is 15 | |
:exec = (boolean_xor exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15) | |
:boolean = nil | |
:string = ("fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 20 steps (last step: boolean_xor): | |
;; missing arguments | |
:exec = (exec_swap (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) false) | |
:integer = (15) | |
:boolean = nil | |
:string = ("fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 21 steps (last step: exec_swap): | |
;; swap the order of the top 2 items on :exec | |
:exec = (false (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and)) | |
:integer = (15) | |
:boolean = nil | |
:string = ("fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 22 steps (last step: false): | |
;; boolean literal | |
:exec = ((string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and)) | |
:integer = (15) | |
:boolean = (false) | |
:string = ("fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 23 steps (last step: (...)): | |
;; unwrap code block | |
:exec = (string_dup "buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) | |
:integer = (15) | |
:boolean = (false) | |
:string = ("fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 24 steps (last step: string_dup): | |
;; make a copy of the top item on :string stack | |
:exec = ("buzz" string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) | |
:integer = (15) | |
:boolean = (false) | |
:string = ("fizz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 25 steps (last step: buzz): | |
;; string literal "buzz" | |
:exec = (string_concat exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) | |
:integer = (15) | |
:boolean = (false) | |
:string = ("buzz" "fizz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 26 steps (last step: string_concat): | |
;; concatenate top two items on :string stack | |
:exec = (exec_stackdepth integer_mod string_empty boolean_dup string_shove boolean_and) | |
:integer = (15) | |
:boolean = (false) | |
:string = ("fizzbuzz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 27 steps (last step: exec_stackdepth): | |
;; count how many items on :exec stack | |
:exec = (integer_mod string_empty boolean_dup string_shove boolean_and) | |
:integer = (5 15) | |
:boolean = (false) | |
:string = ("fizzbuzz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 28 steps (last step: integer_mod): | |
;; push (mod 15 5) to :integer | |
:exec = (string_empty boolean_dup string_shove boolean_and) | |
:integer = (0) | |
:boolean = (false) | |
:string = ("fizzbuzz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 29 steps (last step: string_empty): | |
;; push `true` if the :string stack is empty, `false` otherwise | |
:exec = (boolean_dup string_shove boolean_and) | |
:integer = (0) | |
:boolean = (false false) | |
:string = ("fizzbuzz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 30 steps (last step: boolean_dup): | |
;; make a copy of the top :boolean item | |
:exec = (string_shove boolean_and) | |
:integer = (0) | |
:boolean = (false false false) | |
:string = ("fizzbuzz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 31 steps (last step: string_shove): | |
;; again, "shove" the top string down to the indicated position (here, 0) | |
:exec = (boolean_and) | |
:integer = () | |
:boolean = (false false false) | |
:string = ("fizzbuzz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
State after 32 steps (last step: boolean_and): | |
;; push (and false false) | |
:exec = () | |
:integer = () | |
:boolean = (false false) | |
:string = ("fizzbuzz" "fizz" "" "i" "z" "z") | |
:input = (15) | |
;; the :exec stack is empty | |
#clojush.pushstate.PushState{:exec (), :code nil, :integer (), :float nil, :boolean (false false), :char nil, :string ("fizzbuzz" "fizz" "" "i" "z" "z"), :zip nil, :vector_integer nil, :vector_float nil, :vector_boolean nil, :vector_string nil, :input (15), :output nil, :auxiliary nil, :tag nil, :return nil, :environment nil, :genome nil, :termination :normal} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment