poke-devel
[Top][All Lists]
Advanced

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

Re: [RFC] Syntax for appending elements to arrays


From: Jose E. Marchesi
Subject: Re: [RFC] Syntax for appending elements to arrays
Date: Fri, 27 Nov 2020 22:58:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 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.

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



reply via email to

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