How do we name the array/sequence member i.e. element ? e.g.
var a : array[ 3, int ]
# not this:
a[0] = 7
a[1] = 8
a[2] = 9
# but need e.g:
a.left = 7
a[left] =7
a.middle = 8
a[middle] = 8
a.right = 9
a[right] = 9
# (eg. errors sure)
# & other sort of it
You can use an enum type as the index for the array:
type Alignment = enum
Left
Middle
Right
var a: array[Alignment, int]
a[Left] = 7
a[Middle] = 8
a[Right] = 9
# this is also supported:
const b = [
Left: 7,
Middle: 8,
Right: 9
]
# or this:
const c: array[Alignment, int] = [7, 8, 9]
type EnumVals = enum
Left, Middle, Right
var a = [Left: 7, Middle: 8, Right: 9]
a[Left] = 7
a[Middle] = 8
a[Right] = 9
Alternatively, you may use a tuple or object.
var a: tuple[left: int, middle: int, right: int]
a.left = 7
a.middle = 8
a.right = 9
The previous suggestions are much better style but for completeness sake you can also use const to introduce named constants:
const
left = 0
middle = 1
right = 2
var a : array[ 3, int ]
a[left] = 7
a[middle] = 8
a[right] = 9