Add elements to tuples or arrays

I think this is clearly an instance of the XY problem, you are asking for something that you think it is the solution instead of just asking how to solve your real problem. It was not clear (maybe it is not yet, but I think I understand now) what property this function that is not push! or append! should have to satisfy your requirements.

It seems to me that your problem has nothing to do with push! or append!, but the fact that the algorithm (or at least the loop inside it) is badly designed. If you wanna grow a Vector adding an element for each element originally inside it, then just looping over the Vector will not work, as you noticed this ends up as an infinite loop. The first solutions I can think of are either:

  1. Make a copy of the original Vector, iterate over the copy, but make changes to the original, this way the loop will stop where after all the original elements were processed.
  2. (Probably the best.) Just save the length of the original Vector in a variable, and iterate from 1 to this length, this way the loop will also stop after all the original elements were processed, even if the Vector grew in the meantime .
3 Likes