Merge pull request #6 from skwak22/master
ClojureScript namespace changes and small tweaks with dependencies
This commit is contained in:
commit
4de782c50a
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/propeller/.DS_Store
vendored
Normal file
BIN
src/propeller/.DS_Store
vendored
Normal file
Binary file not shown.
0
src/propeller/core.cljc
Normal file → Executable file
0
src/propeller/core.cljc
Normal file → Executable file
0
src/propeller/genome.cljc
Normal file → Executable file
0
src/propeller/genome.cljc
Normal file → Executable file
0
src/propeller/gp.cljc
Normal file → Executable file
0
src/propeller/gp.cljc
Normal file → Executable file
3
src/propeller/problems/simple_regression.cljc
Normal file → Executable file
3
src/propeller/problems/simple_regression.cljc
Normal file → Executable file
@ -58,4 +58,5 @@
|
||||
(assoc individual
|
||||
:behaviors outputs
|
||||
:errors errors
|
||||
:total-error (apply +' errors))))
|
||||
:total-error #?(:clj (apply +' errors)
|
||||
:cljs (apply + errors)))))
|
||||
|
9
src/propeller/problems/software/number_io.cljc
Normal file → Executable file
9
src/propeller/problems/software/number_io.cljc
Normal file → Executable file
@ -5,7 +5,8 @@
|
||||
[propeller.push.utils.helpers :refer [get-stack-instructions]]
|
||||
[propeller.utils :as utils]
|
||||
[propeller.push.state :as state]
|
||||
[propeller.tools.math :as math]))
|
||||
[propeller.tools.math :as math]
|
||||
#?(:cljs [cljs.reader :refer [read-string]])))
|
||||
|
||||
;; =============================================================================
|
||||
;; Tom Helmuth, thelmuth@cs.umass.edu
|
||||
@ -78,7 +79,8 @@
|
||||
inputs)
|
||||
parsed-outputs (map (fn [output]
|
||||
(try (read-string output)
|
||||
(catch Exception e 1000.0)))
|
||||
#?(:clj (catch Exception e 1000.0)
|
||||
:cljs (catch js/Error. e 1000.0))))
|
||||
outputs)
|
||||
errors (map (fn [correct-output output]
|
||||
(min 1000.0 (math/abs (- correct-output output))))
|
||||
@ -87,4 +89,5 @@
|
||||
(assoc individual
|
||||
:behaviors parsed-outputs
|
||||
:errors errors
|
||||
:total-error (apply +' errors)))))
|
||||
:total-error #?(:clj (apply +' errors)
|
||||
:cljs (apply + errors))))))
|
||||
|
3
src/propeller/problems/software/smallest.cljc
Normal file → Executable file
3
src/propeller/problems/software/smallest.cljc
Normal file → Executable file
@ -89,4 +89,5 @@
|
||||
(assoc individual
|
||||
:behaviors outputs
|
||||
:errors errors
|
||||
:total-error (apply +' errors)))))
|
||||
:total-error #?(:clj (apply +' errors)
|
||||
:cljs (apply + errors))))))
|
||||
|
3
src/propeller/problems/string_classification.cljc
Normal file → Executable file
3
src/propeller/problems/string_classification.cljc
Normal file → Executable file
@ -68,4 +68,5 @@
|
||||
(assoc individual
|
||||
:behaviors outputs
|
||||
:errors errors
|
||||
:total-error (apply +' errors))))
|
||||
:total-error #?(:clj (apply +' errors)
|
||||
:cljs (apply + errors)))))
|
BIN
src/propeller/push/.DS_Store
vendored
Normal file
BIN
src/propeller/push/.DS_Store
vendored
Normal file
Binary file not shown.
0
src/propeller/push/core.cljc
Normal file → Executable file
0
src/propeller/push/core.cljc
Normal file → Executable file
4
src/propeller/push/instructions/bool.cljc
Normal file → Executable file
4
src/propeller/push/instructions/bool.cljc
Normal file → Executable file
@ -1,6 +1,8 @@
|
||||
(ns propeller.push.instructions.bool
|
||||
#?(:cljs (:require-macros
|
||||
[propeller.push.utils.macros :refer [def-instruction]]))
|
||||
(:require [propeller.push.utils.helpers :refer [make-instruction]]
|
||||
[propeller.push.utils.macros :refer [def-instruction]]))
|
||||
#?(:clj [propeller.push.utils.macros :refer [def-instruction]])))
|
||||
|
||||
;; =============================================================================
|
||||
;; BOOLEAN Instructions
|
||||
|
10
src/propeller/push/instructions/character.cljc
Normal file → Executable file
10
src/propeller/push/instructions/character.cljc
Normal file → Executable file
@ -1,9 +1,13 @@
|
||||
(ns propeller.push.instructions.character
|
||||
#?(:cljs (:require-macros
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]))
|
||||
(:require [propeller.push.state :as state]
|
||||
[propeller.push.utils.helpers :refer [make-instruction]]
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]
|
||||
[propeller.tools.character :as char]))
|
||||
[propeller.tools.character :as char]
|
||||
#?(:clj
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]])))
|
||||
|
||||
;; =============================================================================
|
||||
;; CHAR Instructions
|
||||
|
15
src/propeller/push/instructions/code.cljc
Normal file → Executable file
15
src/propeller/push/instructions/code.cljc
Normal file → Executable file
@ -1,9 +1,13 @@
|
||||
(ns propeller.push.instructions.code
|
||||
#?(:cljs (:require-macros
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]))
|
||||
(:require [propeller.utils :as utils]
|
||||
[propeller.push.state :as state]
|
||||
[propeller.push.utils.helpers :refer [make-instruction]]
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]))
|
||||
#?(:clj
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]])))
|
||||
|
||||
;; =============================================================================
|
||||
;; CODE Instructions
|
||||
@ -64,8 +68,11 @@
|
||||
popped-state
|
||||
(state/push-to-stack popped-state
|
||||
:exec
|
||||
(list (+' current-index increment)
|
||||
destination-index
|
||||
(list #? (:clj
|
||||
(+' current-index increment)
|
||||
:cljs
|
||||
(+ current-index increment))
|
||||
destination-index
|
||||
:exec_do_range
|
||||
to-do)))]
|
||||
(state/push-to-stack
|
||||
|
3
src/propeller/push/instructions/input_output.cljc
Normal file → Executable file
3
src/propeller/push/instructions/input_output.cljc
Normal file → Executable file
@ -1,4 +1,7 @@
|
||||
(ns propeller.push.instructions.input-output
|
||||
#?(:cljs (:require-macros
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]))
|
||||
(:require [propeller.push.state :as state]
|
||||
[propeller.push.utils.helpers :refer [make-instruction]]
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
|
22
src/propeller/push/instructions/numeric.cljc
Normal file → Executable file
22
src/propeller/push/instructions/numeric.cljc
Normal file → Executable file
@ -1,8 +1,12 @@
|
||||
(ns propeller.push.instructions.numeric
|
||||
#?(:cljs (:require-macros
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]))
|
||||
(:require [propeller.push.utils.helpers :refer [make-instruction]]
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]
|
||||
[propeller.tools.math :as math]))
|
||||
[propeller.tools.math :as math]
|
||||
#?(:cljs [cljs.reader :refer [read-string]]
|
||||
:clj [propeller.push.utils.macros
|
||||
:refer [def-instruction generate-instructions]])))
|
||||
|
||||
;; =============================================================================
|
||||
;; FLOAT and INTEGER Instructions (polymorphic)
|
||||
@ -40,20 +44,23 @@
|
||||
(def _add
|
||||
^{:stacks #{}}
|
||||
(fn [stack state]
|
||||
(make-instruction state +' [stack stack] stack)))
|
||||
#?(:clj (make-instruction state +' [stack stack] stack)
|
||||
:cljs (make-instruction state + [stack stack] stack))))
|
||||
|
||||
;; Pushes the difference of the top two items (i.e. the second item minus the
|
||||
;; top item) onto the same stack
|
||||
(def _subtract
|
||||
^{:stacks #{}}
|
||||
(fn [stack state]
|
||||
(make-instruction state -' [stack stack] stack)))
|
||||
#?(:clj (make-instruction state -' [stack stack] stack)
|
||||
:cljs (make-instruction state - [stack stack] stack))))
|
||||
|
||||
;; Pushes the product of the top two items onto the same stack
|
||||
(def _mult
|
||||
^{:stacks #{}}
|
||||
(fn [stack state]
|
||||
(make-instruction state *' [stack stack] stack)))
|
||||
#?(:clj (make-instruction state *' [stack stack] stack)
|
||||
:cljs (make-instruction state * [stack stack] stack))))
|
||||
|
||||
;; Pushes the quotient of the top two items (i.e. the second item divided by the
|
||||
;; top item) onto the same stack. If the top item is zero, pushes 1
|
||||
@ -105,7 +112,8 @@
|
||||
(fn [stack state]
|
||||
(make-instruction state
|
||||
#(try ((if (= stack :integer) int float) (read-string %))
|
||||
(catch Exception e))
|
||||
#?(:clj (catch Exception e)
|
||||
:cljs (catch js/Error. e)))
|
||||
[:string]
|
||||
stack)))
|
||||
|
||||
|
8
src/propeller/push/instructions/polymorphic.cljc
Normal file → Executable file
8
src/propeller/push/instructions/polymorphic.cljc
Normal file → Executable file
@ -1,9 +1,13 @@
|
||||
(ns propeller.push.instructions.polymorphic
|
||||
#?(:cljs (:require-macros
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]))
|
||||
(:require [propeller.utils :as utils]
|
||||
[propeller.push.state :as state]
|
||||
[propeller.push.utils.helpers :refer [make-instruction]]
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]]))
|
||||
#?(:clj
|
||||
[propeller.push.utils.macros :refer [def-instruction
|
||||
generate-instructions]])))
|
||||
|
||||
;; =============================================================================
|
||||
;; Polymorphic Instructions
|
||||
|
6
src/propeller/push/instructions/string.cljc
Normal file → Executable file
6
src/propeller/push/instructions/string.cljc
Normal file → Executable file
@ -1,9 +1,11 @@
|
||||
(ns propeller.push.instructions.string
|
||||
#?(:cljs (:require-macros
|
||||
[propeller.push.utils.macros :refer [def-instruction]]))
|
||||
(:require [clojure.string :as string]
|
||||
[propeller.utils :as utils]
|
||||
[propeller.push.utils.helpers :refer [make-instruction]]
|
||||
[propeller.push.utils.macros :refer [def-instruction]]
|
||||
[propeller.push.state :as state]))
|
||||
[propeller.push.state :as state]
|
||||
#?(:clj [propeller.push.utils.macros :refer [def-instruction]])))
|
||||
|
||||
;; =============================================================================
|
||||
;; STRING Instructions
|
||||
|
5
src/propeller/push/instructions/vector.cljc
Normal file → Executable file
5
src/propeller/push/instructions/vector.cljc
Normal file → Executable file
@ -1,10 +1,13 @@
|
||||
(ns propeller.push.instructions.vector
|
||||
#?(:cljs (:require-macros
|
||||
[propeller.push.utils.macros :refer [generate-instructions]]))
|
||||
(:require [clojure.string]
|
||||
[propeller.utils :as utils]
|
||||
[propeller.push.state :as state]
|
||||
[propeller.push.utils.helpers :refer [get-vector-literal-type
|
||||
make-instruction]]
|
||||
[propeller.push.utils.macros :refer [generate-instructions]]))
|
||||
#?(:clj
|
||||
[propeller.push.utils.macros :refer [generate-instructions]])))
|
||||
|
||||
;; =============================================================================
|
||||
;; VECTOR Instructions
|
||||
|
8
src/propeller/push/interpreter.cljc
Normal file → Executable file
8
src/propeller/push/interpreter.cljc
Normal file → Executable file
@ -9,7 +9,7 @@
|
||||
[state]
|
||||
(let [popped-state (state/pop-stack state :exec)
|
||||
instruction (first (:exec state))
|
||||
literal-type (get-literal-type instruction)] ; nil for non-literals
|
||||
literal-type (get-literal-type instruction)] ; nil for non-literals
|
||||
(cond
|
||||
;;
|
||||
;; Recognize functional instruction or input instruction
|
||||
@ -31,8 +31,10 @@
|
||||
(update popped-state :exec #(concat %2 %1) instruction)
|
||||
;;
|
||||
:else
|
||||
(throw (Exception. (str "Unrecognized Push instruction in program: "
|
||||
(name instruction)))))))
|
||||
(throw #?(:clj (Exception. (str "Unrecognized Push instruction in program: "
|
||||
(name instruction)))
|
||||
:cljs (js/Error. (str "Unrecognized Push instruction in program: "
|
||||
(name instruction))))))))
|
||||
|
||||
(defn interpret-program
|
||||
"Runs the given problem starting with the stacks in start-state."
|
||||
|
0
src/propeller/push/state.cljc
Normal file → Executable file
0
src/propeller/push/state.cljc
Normal file → Executable file
16
src/propeller/push/utils/helpers.cljc
Normal file → Executable file
16
src/propeller/push/utils/helpers.cljc
Normal file → Executable file
@ -1,7 +1,10 @@
|
||||
(ns propeller.push.utils.helpers
|
||||
(:require [clojure.set]
|
||||
[propeller.push.core :as push]
|
||||
[propeller.push.state :as state]))
|
||||
[propeller.push.state :as state]
|
||||
#?(:cljs [goog.string :as gstring])
|
||||
#?(:cljs [goog.string.format])))
|
||||
|
||||
|
||||
;; Takes a state and a collection of stacks to take args from. If there are
|
||||
;; enough args on each of the desired stacks, returns a map with keys
|
||||
@ -42,8 +45,12 @@
|
||||
(doseq [[instruction-name function] @push/instruction-table]
|
||||
(assert
|
||||
(:stacks (meta function))
|
||||
(format "ERROR: Instruction %s does not have :stacks defined in metadata."
|
||||
(name instruction-name))))
|
||||
#?(:clj (format
|
||||
"ERROR: Instruction %s does not have :stacks defined in metadata."
|
||||
(name instruction-name))
|
||||
:cljs (gstring/format
|
||||
"ERROR: Instruction %s does not have :stacks defined in metadata."
|
||||
(name instruction-name)))))
|
||||
(for [[instruction-name function] @push/instruction-table
|
||||
:when (clojure.set/subset? (:stacks (meta function)) stacks)]
|
||||
instruction-name))
|
||||
@ -80,6 +87,7 @@
|
||||
(defn print-state
|
||||
[state]
|
||||
(doseq [stack (keys state/empty-state)]
|
||||
(printf "%-15s = " stack)
|
||||
#?(:clj (printf "%-15s = " stack)
|
||||
:cljs (print (gstring/format "%-15s = " stack)))
|
||||
(prn (if (get state stack) (get state stack) '()))
|
||||
(flush)))
|
||||
|
0
src/propeller/push/utils/macros.cljc → src/propeller/push/utils/macros.clj
Normal file → Executable file
0
src/propeller/push/utils/macros.cljc → src/propeller/push/utils/macros.clj
Normal file → Executable file
0
src/propeller/selection.cljc
Normal file → Executable file
0
src/propeller/selection.cljc
Normal file → Executable file
0
src/propeller/session.cljc
Normal file → Executable file
0
src/propeller/session.cljc
Normal file → Executable file
0
src/propeller/tools/calculus.cljc
Normal file → Executable file
0
src/propeller/tools/calculus.cljc
Normal file → Executable file
0
src/propeller/tools/character.cljc
Normal file → Executable file
0
src/propeller/tools/character.cljc
Normal file → Executable file
0
src/propeller/tools/distributions.cljc
Normal file → Executable file
0
src/propeller/tools/distributions.cljc
Normal file → Executable file
0
src/propeller/tools/math.cljc
Normal file → Executable file
0
src/propeller/tools/math.cljc
Normal file → Executable file
0
src/propeller/tools/metrics.cljc
Normal file → Executable file
0
src/propeller/tools/metrics.cljc
Normal file → Executable file
0
src/propeller/utils.cljc
Normal file → Executable file
0
src/propeller/utils.cljc
Normal file → Executable file
0
src/propeller/variation.cljc
Normal file → Executable file
0
src/propeller/variation.cljc
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user