Merge pull request #266 from paultag/paultag/feature/yield-from
Paultag/feature/yield from
This commit is contained in:
commit
b5b2ec4896
6
hy/core/macros.hy
Normal file
6
hy/core/macros.hy
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
;;; hy core macros
|
||||||
|
|
||||||
|
(defmacro yield-from [_hy_yield_from_els]
|
||||||
|
(quasiquote
|
||||||
|
(for [_hy_yield_from_x (unquote _hy_yield_from_els)]
|
||||||
|
(yield _hy_yield_from_x))))
|
18
hy/macros.py
18
hy/macros.py
@ -31,10 +31,14 @@ from hy.util import str_type
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
MACROS = [
|
CORE_MACROS = [
|
||||||
"hy.core.bootstrap",
|
"hy.core.bootstrap",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
EXTRA_MACROS = [
|
||||||
|
"hy.core.macros",
|
||||||
|
]
|
||||||
|
|
||||||
_hy_macros = defaultdict(dict)
|
_hy_macros = defaultdict(dict)
|
||||||
|
|
||||||
|
|
||||||
@ -74,7 +78,7 @@ _wrappers = {
|
|||||||
|
|
||||||
|
|
||||||
def process(tree, module_name):
|
def process(tree, module_name):
|
||||||
load_macros()
|
load_macros(module_name)
|
||||||
old = None
|
old = None
|
||||||
while old != tree:
|
while old != tree:
|
||||||
old = tree
|
old = tree
|
||||||
@ -82,8 +86,14 @@ def process(tree, module_name):
|
|||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
||||||
def load_macros():
|
def load_macros(module_name):
|
||||||
for module in MACROS:
|
for module in CORE_MACROS:
|
||||||
|
__import__(module)
|
||||||
|
|
||||||
|
if module_name.startswith("hy.core"):
|
||||||
|
return
|
||||||
|
|
||||||
|
for module in EXTRA_MACROS:
|
||||||
__import__(module)
|
__import__(module)
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,3 +91,11 @@
|
|||||||
(assert initialized)
|
(assert initialized)
|
||||||
(assert (test-initialized))
|
(assert (test-initialized))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-yield-from []
|
||||||
|
"NATIVE: testing yield from"
|
||||||
|
(defn yield-from-test []
|
||||||
|
(for [i (range 3)]
|
||||||
|
(yield i))
|
||||||
|
(yield-from [1 2 3]))
|
||||||
|
(assert (= (list (yield-from-test)) [0 1 2 1 2 3])))
|
||||||
|
Loading…
Reference in New Issue
Block a user