Created
July 2, 2019 20:53
-
-
Save takemyoxygen/1fd9711cefd2d68aa7b69404c0be4356 to your computer and use it in GitHub Desktop.
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
(defn in? | |
[xs x] | |
(some #(= x %) xs)) | |
(defn unwrap | |
[xs] | |
(if (and (list? xs) (list? (first xs)) (nil? (next xs))) | |
(first xs) | |
xs)) | |
(defn replace-op | |
[operators expr] | |
(let [[left op right & rest] expr] | |
(println (str "left: " left ", op: " op ", right: " right ", rest: " rest)) | |
(cond | |
(nil? op) (list left) | |
(in? operators op) (replace-op operators (cons (list op left right) rest)) | |
:else (concat (list left op) (replace-op operators (cons right rest)))))) | |
(defmacro eval-arithmetic | |
[expression] | |
(->> expression | |
(replace-op ['* '/]) | |
(replace-op ['+ '-]) | |
unwrap)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment