Macro if-python2 for compile-time choice between Python 2 and Python 3 code branches
This commit is contained in:
parent
e693a0267a
commit
b11f2fcf49
@ -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)]
|
||||
|
@ -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))))
|
||||
|
Loading…
Reference in New Issue
Block a user