Thanks infogulch for the library.
However, it's a bit problematic setting a second element without a first, as the first delimiter is removed and the array is reduced by the first (empty) element:
Code:
Array1 := SA_Set(Array1, "Value", 1, 0)
Array2 := SA_Set(Array2, "Value", 2, 0)
msgbox %Array1%`n%Array2%
produces:
Code:
---------------------------
test.ahk
---------------------------
Value
Value
---------------------------
OK
---------------------------
########################################################
Also, it seems that overwriting with named indexes is a bit flaky as I find I end up losing the name despite not specifying GiveName.
Code:
Array := SA_Set(Array, "Value1", 1, "+1", "name")
Array := SA_Set(Array, "Value2", "name", 0)
msgbox %Array%
produces
Code:
---------------------------
test.ahk
---------------------------
Value2
---------------------------
OK
---------------------------
Additionally, although the recognition of names appears to be case sensitive, specifying names appears not to be case sensitive since
Code:
Array := SA_Set(Array, "Value1", 1, "+1", "name")
Array := SA_Set(Array, "Value2", "name", 0, "NAME")
msgbox %Array%
still gives me
Code:
---------------------------
test.ahk
---------------------------
Value2
---------------------------
OK
---------------------------
########################################################
I have also found that the _Find... functions do not take into account named indices, such that an element with name "Name" and value "Needle" (stored as "Name:Needle") does not constitute a whole match for the needle "Needle". Additionally,
Code:
Loop 3
Array := SA_Set(Array, "Needle", A_Index, 0)
msgbox % Array "`n" SA_FindCnt(Array, "Needle")
returns
Code:
---------------------------
test.ahk
---------------------------
NeedleNeedleNeedle
2
---------------------------
OK
---------------------------
since it appears that the find is based on matching the needle preceded by the delimiter. However, the first element is never preceded by a delimiter.
Perhaps it may be worthwhile to use the delimiter to
denote elements instead, so that
every element is preceded/followed by "", i.e., store [ele1, ele2, ... , eleN] as
Code:
ele1ele2 ... eleN ; or
ele1ele2 ... eleN
otherwise you will keep having to find various ways to account for the first element separately (i.e. having to change counts by +/-1 or have to check the last item separately in the SA_FindCnt() etc.), which is just a constant pain to do, and just requires more lines of code and leaves space for bugs.
########################################################
Code:
; !Important Note:
; ! The nIdx in SA_Set and Idx in SA_Set_ now only accept names or indexes
; ! and the "add to end + option" is now in the opt param ...
SA_Set( Array, Val, nIdx="1", opt="+1", giveName="" )
Finally, it might be a good idea to update this to the main post as it still says
Quote:
Number Index: (param name Idx may only be a number)
If you want to add a value at the end of the array with SA_Set() use '+' as the first character and the number following will be counted as an offset from the end of the array. This allows you to add it arbitrarily farther than the end. (Note that the default index param is '+1' so you can add it to the end without specifying a number yourself)
...
SA_Set( Array, Val, [nIdx="+1", Insert=false, giveName=""] )
which initially gave me a fair bit of confusion.
Also, since most other languages overwrites elements of the array by default so that Array[j] := "Value" sets the j'th element to "Value", I found it a little counter-intuitive that by default the equivalent in SA, SA_Set(Array, "Value", j), puts it j elements off the end of the array by default. Indeed, the first time I tried creating an array of [1,2,3] (using AHKA notation), I was surprised to find that
Code:
Array := SA_Set(Array, "Value1", 1)
Loop 3
Array := SA_Set(Array, "Value2", 2)
MsgBox %Array%
produced
Code:
---------------------------
test.ahk
---------------------------
123
---------------------------
OK
---------------------------
although this is just down to personal intuition.
Thanks
AHK v1.0.48.5