Working cljs version of propeller
This commit is contained in:
parent
689536b735
commit
baf28a3e79
@ -39,6 +39,13 @@ After page is loaded, you may also start a REPL connected to browser with:
|
|||||||
yarn shadow-cljs cljs-repl app
|
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
|
## Description
|
||||||
|
|
||||||
Propel is an implementation of the Push programming
|
Propel is an implementation of the Push programming
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
[state instruction]
|
[state instruction]
|
||||||
(if-let [input (instruction (:input state))]
|
(if-let [input (instruction (:input state))]
|
||||||
(state/push-to-stack state :exec input)
|
(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
|
;; OUTPUT Instructions
|
||||||
|
@ -1,18 +1,24 @@
|
|||||||
(ns propeller.tools.character)
|
(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
|
(defn is-letter
|
||||||
"Returns true if the given character is a letter, A-Z or a-z."
|
"Returns true if the given character is a letter, A-Z or a-z."
|
||||||
[c]
|
[c]
|
||||||
(<= (int \A) (int c) (int \z)))
|
(<= (get-ascii \A) (get-ascii c) (get-ascii \z)))
|
||||||
|
|
||||||
|
|
||||||
(defn is-digit
|
(defn is-digit
|
||||||
"Returns true if the given character is a digit, 0-9."
|
"Returns true if the given character is a digit, 0-9."
|
||||||
[c]
|
[c]
|
||||||
(<= (int \0) (int c) (int \9)))
|
(<= (get-ascii \0) (get-ascii c) (get-ascii \9)))
|
||||||
|
|
||||||
|
|
||||||
(defn is-whitespace
|
(defn is-whitespace
|
||||||
"Returns true if the given character is whitespace (newline, space, tab)."
|
"Returns true if the given character is whitespace (newline, space, tab)."
|
||||||
[c]
|
[c]
|
||||||
(contains? #{(int \newline) (int \tab) (int \space)} (int c)))
|
(contains? #{(get-ascii \newline) (get-ascii \tab) (get-ascii \space)} (get-ascii c)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user