CatchTheTornado/askql

[askscript] How about we implement push/append to an array?

czerwinskilukasz1 opened this issue · 5 comments

While writing AskScript examples, I wanted to append to an array twice already.
Alas, the best I could do is to write:

arr:set(arr:length, value)

which is not that easy readable.

I'd prefer to have push/append, like in Javascript:

  let result = [];
  for (let i = 1; i <= m; ++i) {
    result.push(n*i);
  }

@czerwinskilukasz1 push is agains the principle of immutable data. If we come up with some syntax sugar it will still translate to:

result = result:push(n*i)

Sure sure, I'm totally fine with result = result:push(elem).

Hey @mhagmajer and @czerwinskilukasz1 , as I have asked elsewhere also, if you could guide me where and what needs to be done to get this fix, I would do so.

I'm new to this codebase, but want to contribute.

Hi Aditya, welcome to AskQL again :)
This task is pretty straightforward, comparing to the one with double let expression. The task is to create a new resource (aka function) called push, which will live in src/askvm/resources/list/, same as set resource, which is currently defined.
Please use src/askvm/resources/list/set.ts as an example how resources are defined and how they work.
Let me know if you have more questions. @avats-dev

Closed with #510 from @bardeutsch 👏