[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-dev] Pflatten off by one error?
// a doubly nested array
a = Pclump(2, Pclump(2, Pclump(5, Pseries())));
x = a.asStream.nextN(18);
x.shape;
// flatten it zero times
b = Pflatten(0, a).asStream;
x = b.asStream.nextN(18);
x.shape // flattened once
// flatten it once
b = Pflatten(1, a).asStream;
x = b.asStream.nextN(18);
x.shape // flattened twice
In the code:
Pflatten : Pclump {
embedInStream { arg event;
var next, nval;
var stream = pattern.asStream;
var nstream = n.asStream;
while {
next = stream.next(event);
nval = nstream.next(event);
next.notNil and: { nval.notNil };
}{
if (next.isKindOf(SequenceableCollection)) {
next = next.flatten(nval);
next.do {|item| event = item.yield };
}{
event = next.yield;
}
}
^event
}
}
probably it should say
Pflatten : Pclump {
embedInStream { arg event;
var next, nval;
var stream = pattern.asStream;
var nstream = n.asStream;
while {
next = stream.next(event);
nval = nstream.next(event);
next.notNil and: { nval.notNil };
}{
if (next.isKindOf(SequenceableCollection)) {
next = next.flatten(nval);
};
event = next.yield;
}
^event
}
}
If we want to avoid breaking code, this could also be documented.
_______________________________________________
sc-dev mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/