[V2-beta] - Sort example 4 Error Topic is solved

Share your ideas as to how the documentation can be improved.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

[V2-beta] - Sort example 4 Error

21 Sep 2021, 17:06

I keep getting an error "Parameter #3 Sort is invalid" on the first sort of the fourth example of the Sort Documentation.

Is this example incorrect?

Code: Select all

MyVar := "This`nis`nan`nexample`nstring`nto`nbe`nsorted"
MsgBox Sort(MyVar,, "LengthSort")
LengthSort(a1, a2, *)
{
    a1 := StrLen(a1), a2 := StrLen(a2)
    return a1 > a2 ? 1 : a1 < a2 ? -1 : 0  ; Sorts according to the lengths determined above.
}

MyVar := "5,3,7,9,1,13,999,-4"
MsgBox Sort(MyVar, "D,", IntegerSort)
IntegerSort(a1, a2, *)
{
    return a1 - a2  ; Sorts in ascending numeric order. This method works only if the difference is never so large as to overflow a signed 64-bit integer.
}

MyVar := "1,2,3,4"
MsgBox Sort(MyVar, "D,", ReverseDirection)  ; Reverses the list so that it contains 4,3,2,1
ReverseDirection(a1, a2, offset)
{
    return offset  ; Offset is positive if a2 came after a1 in the original list; negative otherwise.
}

MyVar := "a bbb cc"
; Sorts in ascending length order; uses a fat arrow function:
MsgBox Sort(MyVar, "D ", (a,b,*) => StrLen(a) - StrLen(b))
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [V2-beta] - Sort example 4 Error

21 Sep 2021, 17:13

the variable where the function was stored should have been used
not a string containing the name of a function
User avatar
Ragnar
Posts: 613
Joined: 30 Sep 2013, 15:25

Re: [V2-beta] - Sort example 4 Error  Topic is solved

22 Sep 2021, 01:53

Thanks for reporting. Change added in PR #492.

Return to “Suggestions on Documentation Improvements”

Who is online

Users browsing this forum: No registered users and 4 guests