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: Sat, 28 Nov 2020 01:11:10 +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.
>
> I agree with this.
>
>> As for insert, we have its semantics in a[N] = ELEM, unless I am missing
>> something..
>
> "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.

Oh I see.  Well, we already have a PVM instruction for that (ains).  So
it doesn't harm to add an a.insert (IDX, VAL) as well.




reply via email to

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