Symbol collectionSym = collectionVar.getSymbol();
Symbol indexSym = indexVar.getSymbol();
Symbol itemSym = itemVar.getSymbol();
// Loop initializer step
Script initializer = new Script(sLoopName + ":init");
initializer.setActivity(activity);
initializer.setBody(new Pair(
Pair.list(Symbol.SET, indexSym,
Pair.list(Symbol.COND,
Pair.list(Pair.list(Symbol.PAIR_P, collectionSym), collectionSym),
Pair.list(Pair.list(Symbol.VECTOR_P, collectionSym), Primitive.ZERO_INTEGER)
)
),
activity.getFlow().getDefaultReturnCode()
));
if (!bUseOldCollectionVar)
{
initializer.setBody(new Pair(
Pair.list(Symbol.SET, collectionSym, collectionExpression),
initializer.getBody()
));
}
activity.addStep(initializer);
// Loop test step
Decision decision = new Decision(sLoopName + ":branch");
Branch loopBody = new Branch();
decision.setActivity(activity);
loopBody.setDecision(decision);
loopBody.setCondition(Pair.list(Symbol.COND,
Pair.list(Pair.list(Symbol.PAIR_P, collectionSym),
Pair.list(Symbol.NOT, Pair.list(Symbol.NULL_P, indexSym))),
Pair.list(Pair.list(Symbol.VECTOR_P, collectionSym),
Pair.list(Symbol.LT, indexSym, Pair.list(Symbol.VECTOR_LENGTH, collectionSym))),
Pair.list(Symbol.ELSE,
Pair.list(collectionSym, Pair.quote(XMLMetadataLoader.HAS_NEXT)))
));
// Get current item and advance to next step
Script getItem = new Script(sLoopName + ":next");
getItem.setActivity(loopBody);
getItem.setBody(new Pair(
Pair.list(Symbol.COND,
Pair.list(Pair.list(Symbol.PAIR_P, collectionSym),
Pair.list(Symbol.SET, itemSym, Pair.list(Symbol.CAR, indexSym)),
Pair.list(Symbol.SET, indexSym, Pair.list(Symbol.CDR, indexSym))
),