From 1ec9f55741ae54f5e618e248ee49aff132017247 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 28 Aug 2006 21:47:42 +0000 Subject: [PATCH] * In toString, deal with nested lists properly (i.e., flatten them). --- src/libexpr/primops.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index b9f625e8bc..5496e945e3 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -69,6 +69,26 @@ static Expr primImport(EvalState & state, const ATermVector & args) } +static void flattenList(EvalState & state, Expr e, ATermList & result) +{ + ATermList es; + e = evalExpr(state, e); + if (matchList(e, es)) + for (ATermIterator i(es); i; ++i) + flattenList(state, *i, result); + else + result = ATinsert(result, e); +} + + +ATermList flattenList(EvalState & state, Expr e) +{ + ATermList result = ATempty; + flattenList(state, e, result); + return ATreverse(result); +} + + void toString(EvalState & state, Expr e, ATermList & context, string & result) { @@ -135,6 +155,7 @@ void toString(EvalState & state, Expr e, } else if (matchList(e, es)) { + es = flattenList(state, e); bool first = true; for (ATermIterator i(es); i; ++i) { if (!first) result += " "; else first = false;