Request for shorthand to define maps
Posted: 24 Jan 2024, 03:53
AHK has shorthand notation for defining objects and for defining arrays that make writing multidimensional objects, multidimensional arrays, and mixtures of the two relatively easy.'
3x3 2D OBJECT
Uses curly brackets, colons, and commas.
3x3 2D ARRAY
Uses square brackets and commas.
UNFORTUNATELY, AHK does not appear to have a similar shorthand notation for defining maps. The notations would make writing map definitions easier and writing multidimensional maps definitions markedly easier. With multidimensional maps the number of call statements [Map()] increases almost exponentially as the number of dimensions and the number of entries per dimension increases.
NOTE: I have substituted integers for the keys in the map examples below. This gets rid of the need for quotes, makes the code more readable, and makes the code easier to compare to the code for the multidimensional object and array examples.
Below is a "best working" format for a multidimensional map
3x3 2D MAP
Uses calls and commas.
IT WOULD BE NICE IF THE SAME 3x3 2D MAP COULD BE WRITTEN AS:
mGrid := [1:[1:1,2:2,3:3],
2:[1:4,2:5,3:6],
3:[1:7,2:8,3:9]]
Using square brackets, colons, and commas.
THANKS
3x3 2D OBJECT
Code: Select all
oGrid := {1:{1:1,2:2,3:3},
2:{1:4,2:5,3:6},
3:{1:7,2:8,3:9}}
3x3 2D ARRAY
Code: Select all
aGrid := [[1,2,3],
[4,5,6],
[7,8,9]]
UNFORTUNATELY, AHK does not appear to have a similar shorthand notation for defining maps. The notations would make writing map definitions easier and writing multidimensional maps definitions markedly easier. With multidimensional maps the number of call statements [Map()] increases almost exponentially as the number of dimensions and the number of entries per dimension increases.
NOTE: I have substituted integers for the keys in the map examples below. This gets rid of the need for quotes, makes the code more readable, and makes the code easier to compare to the code for the multidimensional object and array examples.
Below is a "best working" format for a multidimensional map
3x3 2D MAP
Code: Select all
mGrid := Map(1,Map(1,1, 2,2, 3,3),
2,Map(1,4, 2,5, 3,6),
3,Map(1,7, 2,8, 3,9))
IT WOULD BE NICE IF THE SAME 3x3 2D MAP COULD BE WRITTEN AS:
mGrid := [1:[1:1,2:2,3:3],
2:[1:4,2:5,3:6],
3:[1:7,2:8,3:9]]
Using square brackets, colons, and commas.
THANKS