[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] Syntax for appending elements to arrays

From: Egeyar Bagcioglu
Subject: Re: [RFC] Syntax for appending elements to arrays
Date: Fri, 27 Nov 2020 23:19:56 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

On 11/27/20 10:58 PM, Jose E. Marchesi wrote:
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...


([1,2,3]).push (4)

     - Side-effect: [1,2,3] -> [1,2,3,4]
     - Evals to [1,2,3,4]


     - Side-effect: [1,2,3] -> [1,2]
     - Evals to 3.
     - Throws E_out_of_bounds if array is empty.

I agree with this.

As for insert, we have its semantics in a[N] = ELEM, unless I am missing

"a[N] = elem" writes "elem" over the value at index N. On the other hand "insert" pushes the current a[N] and all the following values one index down and adds a new element at index N. It can be useful at times. I am leaving it to you to evaluate if we would need that functionality in the context of poke.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]