[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: |
Thu, 26 Nov 2020 09:34:52 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> At the moment we support concatenating arrays by creating new array
> values:
>
> [1,2,3] + [4,5,6] -> evaluates to a new array value [1,2,3,4,5,6]
>
> However, in poke we can have really BIG arrays, and the above can become
> problematic in terms of memory consumption and also performance.
>
> So I suggest adding syntax to append new elements to existing array
> values. I see two options here:
>
> 1) To do it in an expression, like:
>
> [1,2,3] + 4 -> appends 4 to the given array and then evaluates to
> the modified array.
>
> This would of course imply the availability of the corresponding
> statement:
>
> var a = [1,2,3];
> a += 4;
>
>
> 2) To only allow the statement form:
>
> var a = [1,2,3];
> a += 4;
>
> I think I am inclined for 2) more than for 1), because it makes the
> side-effect more explicit.
>
> A disadvantage of 2) is that not allowing `[1,2,3] + 4' may be
> unexpected for the programmer.
>
> Opinions?
I just realized 2) is unfortunately ambiguous with the existing
array-concatenation operation. If you have:
var a = [[1,2],[3,4]];
And you do:
a += [5,6];
Are you actually trying to concatenate the arrays [[1,2],[3,4]] and
[5,6], in which case you want a syntax error, or
Are you actually tring to append an element [5,6]?
If no one comes with some sane syntax for this, we will have to resort
to the usual notation:
a.push ([5,6]) or,
a.append ([5,6])
But I would really want to avoid that if possible..
No more ideas, anyone?
- [RFC] Syntax for appending elements to arrays, Jose E. Marchesi, 2020/11/25
- Re: [RFC] Syntax for appending elements to arrays, Mohammad-Reza Nabipoor, 2020/11/25
- Re: [RFC] Syntax for appending elements to arrays, Dan Čermák, 2020/11/25
- Re: [RFC] Syntax for appending elements to arrays,
Jose E. Marchesi <=
- Re: [RFC] Syntax for appending elements to arrays, Mohammad-Reza Nabipoor, 2020/11/26
- Re: [RFC] Syntax for appending elements to arrays, Jose E. Marchesi, 2020/11/27
- Re: [RFC] Syntax for appending elements to arrays, Jose E. Marchesi, 2020/11/27
- Re: [RFC] Syntax for appending elements to arrays, Egeyar Bagcioglu, 2020/11/27
- Re: [RFC] Syntax for appending elements to arrays, Jose E. Marchesi, 2020/11/27
- Re: [RFC] Syntax for appending elements to arrays, Egeyar Bagcioglu, 2020/11/27
- Re: [RFC] Syntax for appending elements to arrays, Jose E. Marchesi, 2020/11/27