Modify

#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 Nutster, on Oct 26, 2009 at 7:07:16 PM

Owner: set to Nutster
Status: newassigned

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

comment:2 by Jon, on Oct 26, 2009 at 8:35:48 PM

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:3 by anonymous, on Oct 28, 2009 at 8:27:37 PM

I think that [1,2,2,3] would be the most logical output in the example.

comment:4 by Valik, on Oct 28, 2009 at 9:43:07 PM

I could argue that [3,4] should be the output.

comment:5 by Gabriel13, on Oct 28, 2009 at 10:22:09 PM

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 Valik, on Oct 31, 2009 at 8:34:11 PM

Type: BugFeature Request
Version: 3.3.0.0

Since this is not a bug I'm changing it to a feature request.

comment:7 by Nutster, on Mar 11, 2010 at 9:02:04 PM

Resolution: Rejected
Status: assignedclosed

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.

Modify Ticket

Action
as closed The owner will remain Nutster.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.