diff --git a/NEWS b/NEWS index 2c52152..338c7e6 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ Changes from 0.13.0 [ Language Changes ] + * The unquote-splice or ~@ form now accepts any false value as empty. * `yield-from` is no longer supported under Python 2 * `apply` has been replaced with Python-style unpacking operators `#*` and `#**` (e.g., `(f #* args #** kwargs)`) diff --git a/hy/compiler.py b/hy/compiler.py index 5fd073f..a0f3589 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -707,7 +707,9 @@ class HyASTCompiler(object): level) imports.update(f_imports) if splice: - to_add = HyExpression([HySymbol("list"), f_contents]) + to_add = HyExpression([ + HySymbol("list"), + HyExpression([HySymbol("or"), f_contents, HyList()])]) else: to_add = HyList([f_contents]) diff --git a/tests/native_tests/quote.hy b/tests/native_tests/quote.hy index 32a11b9..e1c9f3b 100644 --- a/tests/native_tests/quote.hy +++ b/tests/native_tests/quote.hy @@ -74,17 +74,17 @@ (defn test-unquote-splice [] "NATIVE: test splicing unquotes" (setv q (quote (c d e))) - (setv qq (quasiquote (a b (unquote-splice q) f (unquote-splice q)))) - (assert (= (len qq) 9)) - (assert (= qq (quote (a b c d e f c d e))))) + (setv qq `(a b ~@q f ~@q ~@0 ~@False ~@None g ~@(when False 1) h)) + (assert (= (len qq) 11)) + (assert (= qq (quote (a b c d e f c d e g h))))) (defn test-nested-quasiquote [] "NATIVE: test nested quasiquotes" - (setv qq (quasiquote (1 (quasiquote (unquote (+ 1 (unquote (+ 2 3))))) 4))) - (setv q (quote (1 (quasiquote (unquote (+ 1 5))) 4))) + (setv qq `(1 `~(+ 1 ~(+ 2 3) ~@None) 4)) + (setv q (quote (1 `~(+ 1 5) 4))) (assert (= (len q) 3)) - (assert (= (get qq 1) (quote (quasiquote (unquote (+ 1 5)))))) + (assert (= (get qq 1) (quote `~(+ 1 5)))) (assert (= q qq)))