Allow unquote-splice
to accept any false value as empty
This commit is contained in:
parent
d9a5acbcc9
commit
a0224ef8bd
1
NEWS
1
NEWS
@ -1,6 +1,7 @@
|
|||||||
Changes from 0.13.0
|
Changes from 0.13.0
|
||||||
|
|
||||||
[ Language Changes ]
|
[ Language Changes ]
|
||||||
|
* The unquote-splice or ~@ form now accepts any false value as empty.
|
||||||
* `yield-from` is no longer supported under Python 2
|
* `yield-from` is no longer supported under Python 2
|
||||||
* `apply` has been replaced with Python-style unpacking operators `#*` and
|
* `apply` has been replaced with Python-style unpacking operators `#*` and
|
||||||
`#**` (e.g., `(f #* args #** kwargs)`)
|
`#**` (e.g., `(f #* args #** kwargs)`)
|
||||||
|
@ -707,7 +707,9 @@ class HyASTCompiler(object):
|
|||||||
level)
|
level)
|
||||||
imports.update(f_imports)
|
imports.update(f_imports)
|
||||||
if splice:
|
if splice:
|
||||||
to_add = HyExpression([HySymbol("list"), f_contents])
|
to_add = HyExpression([
|
||||||
|
HySymbol("list"),
|
||||||
|
HyExpression([HySymbol("or"), f_contents, HyList()])])
|
||||||
else:
|
else:
|
||||||
to_add = HyList([f_contents])
|
to_add = HyList([f_contents])
|
||||||
|
|
||||||
|
@ -74,17 +74,17 @@
|
|||||||
(defn test-unquote-splice []
|
(defn test-unquote-splice []
|
||||||
"NATIVE: test splicing unquotes"
|
"NATIVE: test splicing unquotes"
|
||||||
(setv q (quote (c d e)))
|
(setv q (quote (c d e)))
|
||||||
(setv qq (quasiquote (a b (unquote-splice q) f (unquote-splice q))))
|
(setv qq `(a b ~@q f ~@q ~@0 ~@False ~@None g ~@(when False 1) h))
|
||||||
(assert (= (len qq) 9))
|
(assert (= (len qq) 11))
|
||||||
(assert (= qq (quote (a b c d e f c d e)))))
|
(assert (= qq (quote (a b c d e f c d e g h)))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-nested-quasiquote []
|
(defn test-nested-quasiquote []
|
||||||
"NATIVE: test nested quasiquotes"
|
"NATIVE: test nested quasiquotes"
|
||||||
(setv qq (quasiquote (1 (quasiquote (unquote (+ 1 (unquote (+ 2 3))))) 4)))
|
(setv qq `(1 `~(+ 1 ~(+ 2 3) ~@None) 4))
|
||||||
(setv q (quote (1 (quasiquote (unquote (+ 1 5))) 4)))
|
(setv q (quote (1 `~(+ 1 5) 4)))
|
||||||
(assert (= (len q) 3))
|
(assert (= (len q) 3))
|
||||||
(assert (= (get qq 1) (quote (quasiquote (unquote (+ 1 5))))))
|
(assert (= (get qq 1) (quote `~(+ 1 5))))
|
||||||
(assert (= q qq)))
|
(assert (= q qq)))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user