Add a `when' macro
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
9b261a5004
commit
f68e3b972b
@ -170,3 +170,14 @@ def drop_macro(tree):
|
||||
return HyExpression([HySymbol('slice'),
|
||||
ret,
|
||||
HyInteger(n)])
|
||||
|
||||
|
||||
@macro("when")
|
||||
def when_macro(tree):
|
||||
tree.pop(0) # "when"
|
||||
test = tree.pop(0)
|
||||
return HyExpression([
|
||||
HySymbol('if'),
|
||||
test,
|
||||
HyExpression([HySymbol("do")]) + tree,
|
||||
])
|
||||
|
@ -4,3 +4,4 @@
|
||||
import hy # noqa
|
||||
from .native_tests.math import * # noqa
|
||||
from .native_tests.language import * # noqa
|
||||
from .native_tests.when import * # noqa
|
||||
|
8
tests/native_tests/when.hy
Normal file
8
tests/native_tests/when.hy
Normal file
@ -0,0 +1,8 @@
|
||||
(defn test-when []
|
||||
"NATIVE: test when"
|
||||
(assert (= (when true 1) 1))
|
||||
(assert (= (when true 1 2) 2))
|
||||
(assert (= (when true 1 3) 3))
|
||||
(assert (= (when false 2) null))
|
||||
(assert (= (when (= 1 2) 42) null))
|
||||
(assert (= (when (= 2 2) 42) 42)))
|
Loading…
Reference in New Issue
Block a user