diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5a9bc55 Binary files /dev/null and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..70cf722 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/propeller/.DS_Store b/src/propeller/.DS_Store new file mode 100644 index 0000000..0d0fca7 Binary files /dev/null and b/src/propeller/.DS_Store differ diff --git a/src/propeller/core.cljc b/src/propeller/core.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/genome.cljc b/src/propeller/genome.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/gp.cljc b/src/propeller/gp.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/problems/simple_regression.cljc b/src/propeller/problems/simple_regression.cljc old mode 100644 new mode 100755 index bc734ff..9606826 --- a/src/propeller/problems/simple_regression.cljc +++ b/src/propeller/problems/simple_regression.cljc @@ -58,4 +58,5 @@ (assoc individual :behaviors outputs :errors errors - :total-error (apply +' errors)))) + :total-error #?(:clj (apply +' errors) + :cljs (apply + errors))))) diff --git a/src/propeller/problems/software/number_io.cljc b/src/propeller/problems/software/number_io.cljc old mode 100644 new mode 100755 index ab42d25..698feaf --- a/src/propeller/problems/software/number_io.cljc +++ b/src/propeller/problems/software/number_io.cljc @@ -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)))))) diff --git a/src/propeller/problems/software/smallest.cljc b/src/propeller/problems/software/smallest.cljc old mode 100644 new mode 100755 index 9641cfa..7e8c3fb --- a/src/propeller/problems/software/smallest.cljc +++ b/src/propeller/problems/software/smallest.cljc @@ -89,4 +89,5 @@ (assoc individual :behaviors outputs :errors errors - :total-error (apply +' errors))))) + :total-error #?(:clj (apply +' errors) + :cljs (apply + errors)))))) diff --git a/src/propeller/problems/string_classification.cljc b/src/propeller/problems/string_classification.cljc old mode 100644 new mode 100755 index 9811d2a..4d29056 --- a/src/propeller/problems/string_classification.cljc +++ b/src/propeller/problems/string_classification.cljc @@ -68,4 +68,5 @@ (assoc individual :behaviors outputs :errors errors - :total-error (apply +' errors)))) \ No newline at end of file + :total-error #?(:clj (apply +' errors) + :cljs (apply + errors))))) \ No newline at end of file diff --git a/src/propeller/push/.DS_Store b/src/propeller/push/.DS_Store new file mode 100644 index 0000000..8544a8f Binary files /dev/null and b/src/propeller/push/.DS_Store differ diff --git a/src/propeller/push/core.cljc b/src/propeller/push/core.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/push/instructions/bool.cljc b/src/propeller/push/instructions/bool.cljc old mode 100644 new mode 100755 index aebc7fd..07004f9 --- a/src/propeller/push/instructions/bool.cljc +++ b/src/propeller/push/instructions/bool.cljc @@ -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 diff --git a/src/propeller/push/instructions/character.cljc b/src/propeller/push/instructions/character.cljc old mode 100644 new mode 100755 index 1ed50aa..d858a5b --- a/src/propeller/push/instructions/character.cljc +++ b/src/propeller/push/instructions/character.cljc @@ -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 diff --git a/src/propeller/push/instructions/code.cljc b/src/propeller/push/instructions/code.cljc old mode 100644 new mode 100755 index 010f61d..405fdc9 --- a/src/propeller/push/instructions/code.cljc +++ b/src/propeller/push/instructions/code.cljc @@ -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 diff --git a/src/propeller/push/instructions/input_output.cljc b/src/propeller/push/instructions/input_output.cljc old mode 100644 new mode 100755 index ed9b6b5..e5fccd4 --- a/src/propeller/push/instructions/input_output.cljc +++ b/src/propeller/push/instructions/input_output.cljc @@ -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 diff --git a/src/propeller/push/instructions/numeric.cljc b/src/propeller/push/instructions/numeric.cljc old mode 100644 new mode 100755 index 19eadc3..0822081 --- a/src/propeller/push/instructions/numeric.cljc +++ b/src/propeller/push/instructions/numeric.cljc @@ -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))) diff --git a/src/propeller/push/instructions/polymorphic.cljc b/src/propeller/push/instructions/polymorphic.cljc old mode 100644 new mode 100755 index c2958d2..696ef39 --- a/src/propeller/push/instructions/polymorphic.cljc +++ b/src/propeller/push/instructions/polymorphic.cljc @@ -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 diff --git a/src/propeller/push/instructions/string.cljc b/src/propeller/push/instructions/string.cljc old mode 100644 new mode 100755 index 103c65c..7d88e03 --- a/src/propeller/push/instructions/string.cljc +++ b/src/propeller/push/instructions/string.cljc @@ -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 diff --git a/src/propeller/push/instructions/vector.cljc b/src/propeller/push/instructions/vector.cljc old mode 100644 new mode 100755 index fa9fd10..cf88860 --- a/src/propeller/push/instructions/vector.cljc +++ b/src/propeller/push/instructions/vector.cljc @@ -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 diff --git a/src/propeller/push/interpreter.cljc b/src/propeller/push/interpreter.cljc old mode 100644 new mode 100755 index 4aa9d24..0e01fb2 --- a/src/propeller/push/interpreter.cljc +++ b/src/propeller/push/interpreter.cljc @@ -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." diff --git a/src/propeller/push/state.cljc b/src/propeller/push/state.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/push/utils/helpers.cljc b/src/propeller/push/utils/helpers.cljc old mode 100644 new mode 100755 index 1feb201..46eb572 --- a/src/propeller/push/utils/helpers.cljc +++ b/src/propeller/push/utils/helpers.cljc @@ -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))) diff --git a/src/propeller/push/utils/macros.cljc b/src/propeller/push/utils/macros.clj old mode 100644 new mode 100755 similarity index 100% rename from src/propeller/push/utils/macros.cljc rename to src/propeller/push/utils/macros.clj diff --git a/src/propeller/selection.cljc b/src/propeller/selection.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/session.cljc b/src/propeller/session.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/tools/calculus.cljc b/src/propeller/tools/calculus.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/tools/character.cljc b/src/propeller/tools/character.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/tools/distributions.cljc b/src/propeller/tools/distributions.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/tools/math.cljc b/src/propeller/tools/math.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/tools/metrics.cljc b/src/propeller/tools/metrics.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/utils.cljc b/src/propeller/utils.cljc old mode 100644 new mode 100755 diff --git a/src/propeller/variation.cljc b/src/propeller/variation.cljc old mode 100644 new mode 100755