return makeResult(concreteType, newAppl, ctx);
}
private IValue flatten(IConstructor prod, IList args) {
IListWriter result = vf.listWriter(Factory.Args.getElementType());
int delta = getDelta(prod);
for (int i = 0; i < args.length(); i+=(delta + 1)) {
IConstructor tree = (IConstructor) args.get(i);
if (TreeAdapter.isList(tree) && TreeAdapter.isAppl(tree)) {
if (ProductionAdapter.shouldFlatten(prod, TreeAdapter.getProduction(tree))) {
IList nestedArgs = TreeAdapter.getArgs(tree);
if (nestedArgs.length() > 0) {
appendSeparators(args, result, delta, i);
result.appendAll(nestedArgs);
}
else {
// skip following separators
i += delta;
}
}
else {
appendSeparators(args, result, delta, i);
result.append(tree);
}
}
else {
appendSeparators(args, result, delta, i);
result.append(tree);
}
}
return result.done();
}