#1191 closed Feature Request (Completed)
Make explicit size of arrays optional when have explicit initialization
| Reported by: | jchd | Owned by: | trancexx |
|---|---|---|---|
| Milestone: | 3.3.9.3 | Component: | AutoIt |
| Version: | Severity: | None | |
| Keywords: | Cc: |
Description
Would it be possible that the declaration of arrays doesn't mandate explicit sizes.
$ar[4] = [ 'I', 'have', 'four', 'elements!']
could then be:
$ar[] = [ 'I', 'have', 'four', 'elements!']
and UBound($ar) would then yield 4. Of course, declaring a larger size than number of initializers wouldn't be an error.
I ask because it's very irritating to have to count things when you code initialy, or after you paste a bunch of elements from elsewhere.
Attachments (0)
Change History (8)
comment:1 by , 16 years ago
| Version: | 3.3.1.1 |
|---|
follow-up: 4 comment:3 by , 16 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
In order to make the initialization assignment efficient, the variable gets created first, then the initialization values are assigned to the array elements directly. In order to allow this syntax,
Local $aArray[] = ['This', 'is', 'a', 'test.']
the initializer would need to be read twice, once to determine its size and a second time to assign the values to the array. I will investigate how to do this in a most practical and efficient manner.
I think I will need the empty brackets after the variable name as a marker that I should be looking for array initializers and that I will need to perform the double scan of the initializer.
Local $aArray = ['Pain', 'in', 'the', 'neck', 'array']
This version will not be happening.
comment:4 by , 16 years ago
I think I will need the empty brackets after the variable name as a marker that I should be looking for array initializers and that I will need to perform the double scan of the initializer.
I was suspecting this, so my initial request was suggesting this form. It's also more similar to C and friends and very intuitive.
Do you think you'll be able to generalize to any dimension, as in:
Local $aArray[2][][3] = [ ...
Also since you are at it, can it be made possible to have empty (sub-dimension) initializers:
Local $a2Array[4][3] = [[5], [6, 2, 8], [1], [9, 7]] ;; works fine Local $a2Array[4][3] = [[5], [6, 2, 8], [], [9, 7]] ;; current versions chokes at '[]' Local $a2Array[][] = [[5], [6, 2, 8], [], [9, 7]] ;; would be a must
This isn't exactly the same request but it's so close that I don't want to open yet another ticket.
follow-up: 6 comment:5 by , 16 years ago
AutoIt does not have a legal undefined value, like perl or some other languages. You need to explicitly declare a value in [], even if "" or 0. Without more detail of what [] is supposed to do, this is not going to happen.
comment:6 by , 16 years ago
Replying to Nutster:
AutoIt does not have a legal undefined value, like perl or some other languages. You need to explicitly declare a value in [], even if "" or 0. Without more detail of what [] is supposed to do, this is not going to happen.
Sorry but this doesn't sound very consistent with current behavior. E.g. what value is then given to undeclared elements in $aTest[5] = [1] ?
Since in the multi-dimension scenario, after first pass you know which is the "convex enveloppe" (max dimensions) of the hole thing, I hardly see your point.
comment:7 by , 14 years ago
| Milestone: | → 3.3.9.3 |
|---|---|
| Owner: | changed from to |
| Resolution: | → Completed |
| Status: | assigned → closed |
Added by revision [6882] in version: 3.3.9.3

Automatic ticket cleanup.