In order to not escalate the CVS war, I'll present my solution for how to deal with cyclic arrays in Array.flatten here:
//! Flatten a multi-dimensional array to a one-dimensional array. //! @trows //! @[flatten] throws an error if @[a] is cyclic. array flatten(array a) { array ret=({}); multiset seen = (<>);
void low_flatten(array aa) { foreach(aa, mixed b) if(arrayp(b)) { if(!sizeof([array]b)) continue; if(seen[b]) error("Trying to flatten a cyclic array.\n"); seen[b]=1; low_flatten([array]b); } else ret += ({ b }); }; low_flatten(a); return ret; }
(aside from the fact the programs like the one below hangs pike)
void foo() {
void bar(array i) { error("gazonk\n"); };
array a = ({ 0 }); a[0]=a; bar(a); }