Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (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)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement