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
|
||||
|
||||
[ 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)`)
|
||||
|
@ -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])
|
||||
|
||||
|
@ -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)))
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user