From baf28a3e79767144c2a0af365675f9530f88361c Mon Sep 17 00:00:00 2001 From: skwak22 Date: Wed, 15 Jul 2020 22:23:42 +0900 Subject: [PATCH] Working cljs version of propeller --- .DS_Store | Bin 6148 -> 6148 bytes README.md | 7 +++++++ .../push/instructions/input_output.cljc | 4 +++- src/propeller/tools/character.cljc | 12 +++++++++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.DS_Store b/.DS_Store index 9a874b5768f336915163bb88cd434575b859f936..feca8613504bcd7430524202412f605a970dd548 100644 GIT binary patch delta 24 gcmZoMXfc>z$H*|zUVdZZGWN;3BJ7*FIezj30AOtgj{pDw delta 26 icmZoMXfc>z$H+L*UY?P0W8yOQ$$BDeo4GlD@&f>7?FW(o diff --git a/README.md b/README.md index 63ad5f2..cf514c5 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,13 @@ After page is loaded, you may also start a REPL connected to browser with: yarn shadow-cljs cljs-repl app ``` +Once the REPL is loaded, load the core namespace with: + +``` +(ns propeller.core) +``` +Calling `(-main)` will run the default genetic programming problem. + ## Description Propel is an implementation of the Push programming diff --git a/src/propeller/push/instructions/input_output.cljc b/src/propeller/push/instructions/input_output.cljc index e5fccd4..55db2ee 100755 --- a/src/propeller/push/instructions/input_output.cljc +++ b/src/propeller/push/instructions/input_output.cljc @@ -19,7 +19,9 @@ [state instruction] (if-let [input (instruction (:input state))] (state/push-to-stack state :exec input) - (throw (Exception. (str "Undefined input instruction " instruction))))) + (throw #?(:clj (Exception. (str "Undefined input instruction " instruction)) + :cljs (js/Error + (str "Undefined input instruction " instruction)))))) ;; ============================================================================= ;; OUTPUT Instructions diff --git a/src/propeller/tools/character.cljc b/src/propeller/tools/character.cljc index 32d64d3..6c8b846 100755 --- a/src/propeller/tools/character.cljc +++ b/src/propeller/tools/character.cljc @@ -1,18 +1,24 @@ (ns propeller.tools.character) +(defn get-ascii + "Gets the ASCII code of a char" + [c] + #?(:clj (int c) + :cljs (.charCodeAt c 0))) + (defn is-letter "Returns true if the given character is a letter, A-Z or a-z." [c] - (<= (int \A) (int c) (int \z))) + (<= (get-ascii \A) (get-ascii c) (get-ascii \z))) (defn is-digit "Returns true if the given character is a digit, 0-9." [c] - (<= (int \0) (int c) (int \9))) + (<= (get-ascii \0) (get-ascii c) (get-ascii \9))) (defn is-whitespace "Returns true if the given character is whitespace (newline, space, tab)." [c] - (contains? #{(int \newline) (int \tab) (int \space)} (int c))) + (contains? #{(get-ascii \newline) (get-ascii \tab) (get-ascii \space)} (get-ascii c)))