askql icon indicating copy to clipboard operation
askql copied to clipboard

Implement a swap resource

Open czerwinskilukasz1 opened this issue 4 years ago • 3 comments

@mhagmajer mentioned that swapping 2 indices of the array can be done this way:

arr = arr:set(j, arr:at(i)):set(i, arr:at(j))

How about we simplify it even more and introduce swap? It could work the following way:

  1. For arrays: swap(arr, i, j)

  2. For objects: swap(obj, key1, key2)

As for variables, not sure if we can do it a similar way with our current 'no-pointers' approach. If yes, let's include it, if no, let's create a separate issue for further discussion.

czerwinskilukasz1 avatar Jun 23 '20 11:06 czerwinskilukasz1

I think this is more matter of a useful function to be defined in user space than something we should support explicitly on the vm level. What arguments are there for actually doing this?

mhagmajer avatar Jun 23 '20 11:06 mhagmajer

Also I feel like "swap" is a little confusing as a name given that this function produces a new array rather than making any changes to the referenced one: arr = swap(arr, i, j).

mhagmajer avatar Jun 23 '20 11:06 mhagmajer

"swap" is the name you used, @mhagmajer image We could find a better word later on, I am asking about the functionality itself, not the wording.

Swapping variable values is a common operation and it's very repetitive. By having such a swap feature built in we would make AskScript a bit more friendly than other languages such as C or Javascript.

czerwinskilukasz1 avatar Jun 23 '20 14:06 czerwinskilukasz1