Created
January 19, 2017 22:59
-
-
Save collinalexbell/c1680151a67904ca426087ed82123906 to your computer and use it in GitHub Desktop.
This file contains 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
(defmacro infix [a b c] | |
`(~b ~a ~c)) | |
(defmacro python-fn-call [f a] | |
(if (not (nil? a)) | |
(cons f a) | |
f)) | |
(defmacro python [l] | |
(let [for-index (.indexOf l 'for) | |
inj-clause (subvec l 0 for-index) | |
in-index (.indexOf l 'in) | |
fn-clause (subvec l (+ 1 in-index)) | |
] | |
`(map (fn [~(first inj-clause)] | |
~(if (= 3 (count inj-clause)) | |
`(infix ~(first inj-clause) ~(second inj-clause) ~(nth inj-clause 2)) | |
(first inj-clause))) | |
(python-fn-call ~(first fn-clause) ~(nth fn-clause 1 nil))))) | |
;;tests | |
(infix 2 * 2) | |
(python-fn-call range(10)) | |
(python [x * 2 for x in range(10)]) | |
(python [x * 3 for x in range (10)]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment