scope allSpreads. sclass #Data { int n; L collecting; } sclass #StackEntry { int remaining, take; int position; // position in code O step(L stack, Data d) { //printStruct(stack); if (position == 0) { if (l(d.collecting) >= d.n-1) { L result = listPlus(d.collecting, remaining); popLast(stack); ret result; } position++; } if (position == 1) { if (take <= remaining) { d.collecting.add(take); new StackEntry e; e.remaining = remaining-take; stack.add(e); position++; } else popLast(stack); } else if (position == 2) { removeLast(d.collecting); take++; position = 1; } null; } } static IterableIterator> allSpreads(final int toSpread, final int buckets) { final new Data d; d.n = buckets; d.collecting = new L; final new L stack; new StackEntry e; e.remaining = toSpread; stack.add(e); ret iff(func { while (nempty(stack)) { ping(); try object last(stack).step(stack, d); } ret endMarker(); }); } end scope