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]) imports = set([name])
if isinstance(form, HyList): if isinstance(form, HyList):
if not form:
contents = HyList() contents = HyList()
else:
# If there are arguments, they can be spliced
# so we build a sum...
contents = HyExpression([HySymbol("+"), HyList()])
for x in form: for x in form:
f_imports, f_contents, splice = self._render_quoted_form(x, f_imports, f_contents, splice = self._render_quoted_form(x,
level) level)
imports.update(f_imports) imports.update(f_imports)
if splice: if splice:
contents = HyExpression([HySymbol('+'), to_add = f_contents
contents,
f_contents])
else: else:
contents.append(f_contents) to_add = HyList([f_contents])
return imports, HyExpression(
[HySymbol(name), contents.append(to_add)
contents]
).replace(form), False return imports, HyExpression([HySymbol(name),
contents]).replace(form), False
elif isinstance(form, HySymbol): elif isinstance(form, HySymbol):
return imports, HyExpression([HySymbol(name), return imports, HyExpression([HySymbol(name),

View File

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