Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. (defmacro infix [a b c]
  2. `(~b ~a ~c))
  3.  
  4.  
  5. (defmacro python-fn-call [f a]
  6. (if (not (nil? a))
  7. (cons f a)
  8. f))
  9.  
  10.  
  11. (defmacro python [l]
  12. (let [for-index (.indexOf l 'for)
  13. inj-clause (subvec l 0 for-index)
  14. in-index (.indexOf l 'in)
  15. fn-clause (subvec l (+ 1 in-index))
  16. ]
  17. `(map (fn [~(first inj-clause)]
  18. ~(if (= 3 (count inj-clause))
  19. `(infix ~(first inj-clause) ~(second inj-clause) ~(nth inj-clause 2))
  20. (first inj-clause)))
  21. (python-fn-call ~(first fn-clause) ~(nth fn-clause 1 nil)))))
  22.  
  23.  
  24. ;;tests
  25. (infix 2 * 2)
  26.  
  27. (python-fn-call range(10))
  28.  
  29.  
  30. (python [x * 2 for x in range(10)])
  31.  
  32. (python [x * 3 for x in range (10)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement