Both C++ and Rust vectors pushes at the end and pops from the end. If
you think about the structure of such smart arrays, the end is the
most cost effective place for pushing and popping. Other than these,
both provide an additional "insert" method to insert an element with
the specified index.
That being the case, especially due to C++, I suggest following the
same tradition. If not the "insert", at least let's use "push" and
"pop" keywords in a similar way.
C++ Vector Reference: http://www.cplusplus.com/reference/vector/vector/
Rust Vec Reference: https://doc.rust-lang.org/std/vec/struct.Vec.html
Hm, good suggestion. Our target programmers are more likely to be
familiar with C++ and Rust than with Icon.
Also, adding elements to the beginning of the array would be very
expensive with the current underlying implementation...
So,
([1,2,3]).push (4)
- Side-effect: [1,2,3] -> [1,2,3,4]
- Evals to [1,2,3,4]
([1,2,3]).pop
- Side-effect: [1,2,3] -> [1,2]
- Evals to 3.
- Throws E_out_of_bounds if array is empty.