Modify

Opened 10 years ago

Closed 9 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 Changed 10 years ago by Nutster

  • Owner set to Nutster
  • Status changed from new to assigned

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 Changed 10 years ago by Jon

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 Changed 10 years ago by anonymous

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

comment:4 Changed 10 years ago by Valik

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

comment:5 Changed 10 years ago by Gabriel13

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 Changed 10 years ago by Valik

  • Type changed from Bug to Feature Request
  • Version 3.3.0.0 deleted

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

comment:7 Changed 9 years ago by Nutster

  • Resolution set to Rejected
  • Status changed from assigned to 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.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Nutster.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.