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