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: Egeyar Bagcioglu
Subject: Re: [RFC] Syntax for appending elements to arrays
Date: Fri, 27 Nov 2020 22:35:22 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

Hi Jose,

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

Best regards,
Ege


On 11/27/20 8:47 AM, Jose E. Marchesi wrote:
Adding exceptions and fixing a typo:

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

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

([1,2,3]).pop

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

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

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

([1,2,3]).pull

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





reply via email to

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