Page 1 of 1

Make Arrays Useful

Posted: 23 Feb 2024, 12:47
by iseahound
Arrays leave a lot to be desired in AutoHotkey and are at this point rather inferior to Map().

Issue #1: Allocate Arrays in a single line.

It should be possible to do the following in a single line. Even Python allows this via 5*["default value"]

Code: Select all

a := []
a.length := 5
Issue #2: Add useful methods

.sort() - Should be able to sort array element. Also, should accept a user defined sorting function.
.apply() - Should be able to apply a user defined function to each element of the array.
.fold() - Would allow for some simple functions such as sum(). Make it left to right to avoid lfold and rfold, the user can specify .reverse().
.count() - Counts the number of times an element occurs.
.reverse() - To make iterating backwards possible.

Less Important but still useful:
  • Perhaps setting a zero element turns it into a zero-indexed array.
  • Not sure what to do with IndexError and a[100]?

Re: Make Arrays Useful

Posted: 24 Feb 2024, 01:25
by Chunjee
I also think this would be a great addition

Re: Make Arrays Useful

Posted: 15 May 2024, 16:53
by Ralf_Reddings200244
Yes please, these would be so usefull to have. I was actually hoping some of these would be pressent in V2.