return Closure.make(tail, context, ref);
}
case SHARED_APPEND_EXPRESSION: {
if (exp instanceof Block) {
Block block = (Block)exp;
Expression base = block.getChildren()[0];
Value baseVal;
if (base instanceof Literal) {
baseVal = ((Literal)base).getValue();
} else if (base instanceof VariableReference) {
baseVal = Value.asValue(evaluate(base, EVALUATE_VARIABLE, context, ref));
if (baseVal instanceof MemoClosure && ((MemoClosure)baseVal).isFullyRead()) {
baseVal = ((MemoClosure)baseVal).materialize();
}
} else {
throw new AssertionError("base of shared append expression is of class " + base.getClass());
}
if (baseVal instanceof ShareableSequence && ((ShareableSequence)baseVal).isShareable()) {
List list = ((ShareableSequence)baseVal).getList();
SequenceIterator iter = block.getChildren()[1].iterate(context);
while (true) {
Item i = iter.next();
if (i == null) {
break;
}
list.add(i);
}
return new ShareableSequence(list);
} else {
List list = new ArrayList(20);
SequenceIterator iter = baseVal.iterate();
while (true) {
Item i = iter.next();
if (i == null) {
break;
}
list.add(i);
}
iter = block.getChildren()[1].iterate(context);
while (true) {
Item i = iter.next();
if (i == null) {
break;
}