Macro if-python2 for compile-time choice between Python 2 and Python 3 code branches

This commit is contained in:
Konrad Hinsen 2013-09-02 09:58:35 +02:00
parent e693a0267a
commit b11f2fcf49
2 changed files with 11 additions and 0 deletions

View File

@ -1,5 +1,11 @@
;;; hy core macros
(defmacro if-python2 [python2-form python3-form]
(import sys)
(if (< (get sys.version_info 0) 3)
python2-form
python3-form))
(defmacro yield-from [_hy_yield_from_els]
(quasiquote
(for [_hy_yield_from_x (unquote _hy_yield_from_els)]

View File

@ -99,3 +99,8 @@
(yield i))
(yield-from [1 2 3]))
(assert (= (list (yield-from-test)) [0 1 2 1 2 3])))
(defn test-if-python2 []
(import sys)
(assert (= (get sys.version_info 0)
(if-python2 2 3))))