>On Tue, Jan 20, 2009 at 11:15:02PM +0000, Martin Stjernholm, Roxen IS @ Pike
>developers forum wrote:
>> array a = ({0});
>> for (int i = 1; i < 1000; i++)
>> a += ({i});
>> (To make the example simpler, I start out with the array ({0}) instead
>> of the empty array ({}) since the empty array always is shared.)
>
>is that actually making code faster or is it only to make the logic of
>the problem you are discussing simpler?
Here it is simply to point out the exact problem.
>
>> One alternative is to extend the array type to explicitly allow adding
>> elements to the end destructively. It could perhaps look like this:
>> a[sizeof (a)] = i;
>
>what about possible code that expects this operation to fail?
>
>mixed error = catch{ a[x] = i; };
>if (error)
> write("ooops, we reached the end\n");
Imho, that is an academic problem. I've never seen code like that in a
real program. But, if it's really something we want to solve, it's
probably possible that adding elements destructivly at the end of an
array requires a new/special syntax.