Opened 16 years ago
Closed 16 years ago
#1216 closed Feature Request (Rejected)
Adding arrays working suspiciously
| Reported by: | monoceres | Owned by: | Nutster |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | Severity: | None | |
| Keywords: | arrays autoit adding + | Cc: |
Description
This doesn't seem right to me:
#include <array.au3> Local $a[2]=[1,2] Local $a2[2]=[2,3] Local $a3=$a+$a2 _ArrayDisplay($a3)
Output is [1,2]. Optional output would be the combination of the two arrays, but if that's out of the question, maybe throw an error or something?
Attachments (0)
Change History (7)
comment:1 by , 16 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:2 by , 16 years ago
It's not working because adding arrays is undefined. It actually does nothing atm. $a1 + a2 just leaves you with $a1.
If such a feature were implemented, I'm not even sure what the result should be...
comment:5 by , 16 years ago
I don't think you'd want the "+" operator to work either way with arrays.
For array concatenation, if anything the "&" operator should be borrowed instead, to be consistent with the string concatenation operator already present in AutoIt. [1,2] & [2,3] == [1,2,2,3] would make a lot more sense than trying to use the "+" operator - though using "&" would introduce concatenation ambiguity. What if a string and array are concatenated?
As for non-atomic math operations, that would open the door to all sorts of complex problems. I used to work with a language called Euphoria (http://rapideuphoria.com/), which allows for similar non-atomic math and boolean operations. One casualty of this feature was the inability to consistently implement short-circuit boolean evaluation, since the result could potentially be an array of values.
Aside from that, the implementation could easily become quite complex. Would [1,2] + [2,[3,4]] be allowed? If so, how about 3 + [1,[2,3,[4,5]]]? or [4,5] + 6,7],[8,[9,10]? What if COM objects or other non-numeric data types are contained somewhere within the arrays? And what happens when arrays of differing lengths are involved, such as [1,2] + [3,4,5]?
It's probably simpler and less confusing to simply throw an error whenever arrays are involved in binary math, boolean or concatenation operations.
comment:6 by , 16 years ago
| Type: | Bug → Feature Request |
|---|---|
| Version: | 3.3.0.0 |
Since this is not a bug I'm changing it to a feature request.
comment:7 by , 16 years ago
| Resolution: | → Rejected |
|---|---|
| Status: | assigned → closed |
There are too many ways to implement array mathematics. Use UDF's to perform a specific operation, such as matrix addition or matrix multiplication vs. array concatenation or polynomial multiplication. Each is different and each yields different types of result.
Not going to happen. Rejected.

I will investigate. Did you check @Error after the line that tried to add them?
#include <array.au3> Local $a[2]=[1,2] Local $a2[2]=[2,3] Local $a3=$a+$a2 $error = @Error If $Error > 0 Then Msgbox(0, "Error!", "Error set to " & $Error) Else _ArrayDisplay($a3) Endif