Make sure splicing works at all times

This commit is contained in:
Nicolas Dandrimont 2013-05-11 00:26:37 +02:00
parent e039c73abd
commit 68399b9fc3
2 changed files with 18 additions and 12 deletions

View File

@ -526,21 +526,26 @@ class HyASTCompiler(object):
imports = set([name])
if isinstance(form, HyList):
contents = HyList()
if not form:
contents = HyList()
else:
# If there are arguments, they can be spliced
# so we build a sum...
contents = HyExpression([HySymbol("+"), HyList()])
for x in form:
f_imports, f_contents, splice = self._render_quoted_form(x,
level)
imports.update(f_imports)
if splice:
contents = HyExpression([HySymbol('+'),
contents,
f_contents])
to_add = f_contents
else:
contents.append(f_contents)
return imports, HyExpression(
[HySymbol(name),
contents]
).replace(form), False
to_add = HyList([f_contents])
contents.append(to_add)
return imports, HyExpression([HySymbol(name),
contents]).replace(form), False
elif isinstance(form, HySymbol):
return imports, HyExpression([HySymbol(name),

View File

@ -32,9 +32,10 @@
(defn test-unquote-splice []
"NATIVE: test splicing unquotes"
(setf q (quote (c d e)))
(setf qq (quasiquote (a b (unquote-splice q))))
(assert (= (len qq) 5))
(assert (= qq (quote (a b c d e)))))
(setf 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)))))
(defn test-nested-quasiquote []
"NATIVE: test nested quasiquotes"