• Re: ASORT not sorting

    From Claudio H@21:1/5 to All on Thu Sep 7 15:54:25 2023
    Changing the codeblock from:
    { |x,y| x[4]>=y[4].AND.x[3]>=y[3].AND.x[2]>=y[2].AND.x[6]>=y[6] }
    to:
    { |x,y| x[4]+x[3]+x[2]+STR(x[6],15,2)>=y[4]+y[3]+y[2]+STR(y[6],15,2) }
    solved the problem.

    Why the first expresion which also returns .T. if the elements are in the proper positions, doesnt't work?

    Regards
    Claudio H

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Claudio H@21:1/5 to All on Thu Sep 7 15:26:24 2023
    Hi
    I have a multidimensional array (4 rows, 6 elements each, 5 string and a numeric value) and after ASORTing it I still have all the elements in the same positions and can't find the reason.

    Array aDatos BEFORE sorting (the pipe separator was just for logging):
    TC|##|####|####|1,3| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00

    azz:=ASORT(aDatos,,,{ |x,y| x[4]>y[4].AND.x[3]>y[3].AND.x[2]>y[2].AND.x[6]>y[6] })

    Array aDatos AFTER sorting:
    TC|##|####|####|1,3| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00

    Array azz AFTER sorting (just checking if returned array is different):
    TC|##|####|####|1,3| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00

    Array as EXPECTED after sorting:
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|####|1,3| 0.00

    Any clue?
    Regards
    Claudio H

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Fri Sep 8 09:52:28 2023
    Il 08/09/2023 00:54, Claudio H ha scritto:

    Changing the codeblock from:
    { |x,y| x[4]>=y[4].AND.x[3]>=y[3].AND.x[2]>=y[2].AND.x[6]>=y[6] }
    to:
    { |x,y| x[4]+x[3]+x[2]+STR(x[6],15,2)>=y[4]+y[3]+y[2]+STR(y[6],15,2) }
    solved the problem.

    Why the first expresion which also returns .T. if the elements are in the proper positions, doesnt't work?

    Please write here a reduced example showing the problem.

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ella Stern@21:1/5 to Claudio H on Fri Sep 8 12:11:24 2023
    On Friday, September 8, 2023 at 1:54:27 AM UTC+3, Claudio H wrote:
    Changing the codeblock from:
    { |x,y| x[4]>=y[4].AND.x[3]>=y[3].AND.x[2]>=y[2].AND.x[6]>=y[6] }
    to:
    { |x,y| x[4]+x[3]+x[2]+STR(x[6],15,2)>=y[4]+y[3]+y[2]+STR(y[6],15,2) } solved the problem.

    Why the first expresion which also returns .T. if the elements are in the proper positions, doesnt't work?

    Regards
    Claudio H

    What if you set the order of operations?

    { |x,y| (x[4]>=y[4]).AND.(x[3]>=y[3]).AND.(x[2]>=y[2]).AND.(x[6]>=y[6]) }

    I don't have the docs at hand, but here is the theory (scroll down for the table)
    https://en.wikipedia.org/wiki/Order_of_operations

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Claudio H@21:1/5 to All on Fri Sep 8 15:02:51 2023
    Hi Ella

    Leaving ASORT aside, within a simple IF/ENDIF structure the precedence of the operations involved would not require grouping with ()s like in
    IF a>b .AND. x==0

    Anyway I tested your suggestion but didn't solve the issue.

    Here a reduced self contained example and below the content of the log file generated.

    FUNCTION Main ()

    LOCAL aDatos, aCopia
    LOCAL nHandle, n

    aDatos:=ARRAY(0)
    AADD(aDatos,{"TC","##","####","####","1,3",0.00})
    AADD(aDatos,{"TC","##","####","####","1,3,6",100000.00})
    AADD(aDatos,{"TC","##","####","1036","1,3,12",0.00})
    AADD(aDatos,{"TC","VI","STDR","####","1,6",0.00})

    aCopia:=ACLONE(aDatos)

    nHandle:=HB_FCreate("ASORT.LOG")

    FWRITE(nHandle,"original array"+CHR(13)+CHR(10))
    FOR n:=1 TO LEN(aDatos)
    FWRITE(nHandle,STR(n,2)+"-> "+aDatos[n][1]+"|"+aDatos[n][2]+"|"+aDatos[n][3]+"|"+aDatos[n][4]+"|"+aDatos[n][5]+"|"+STR(aDatos[n][6],15,2)+CHR(13)+CHR(10))
    NEXT n
    FWRITE(nHandle,""+CHR(13)+CHR(10))

    ASORT(aDatos,,,{ |x,y| x[4]>y[4].AND.x[3]>y[3].AND.x[2]>y[2].AND.x[6]>y[6] })

    FWRITE(nHandle,"sorted with { |x,y| x[4]>y[4].AND.x[3]>y[3].AND.x[2]>y[2].AND.x[6]>y[6] }"+CHR(13)+CHR(10))
    FOR n:=1 TO LEN(aDatos)
    FWRITE(nHandle,STR(n,2)+"-> "+aDatos[n][1]+"|"+aDatos[n][2]+"|"+aDatos[n][3]+"|"+aDatos[n][4]+"|"+aDatos[n][5]+"|"+STR(aDatos[n][6],15,2)+CHR(13)+CHR(10))
    NEXT n
    FWRITE(nHandle,""+CHR(13)+CHR(10))

    aDatos:=ACLONE(aCopia)
    ASORT(aDatos,,,{ |x,y| x[4]+x[3]+x[2]+STR(x[6],15,2)>=y[4]+y[3]+y[2]+STR(y[6],15,2) })

    FWRITE(nHandle,"sorted with { |x,y| x[4]+x[3]+x[2]+STR(x[6],15,2)>=y[4]+y[3]+y[2]+STR(y[6],15,2) }"+CHR(13)+CHR(10))
    FOR n:=1 TO LEN(aDatos)
    FWRITE(nHandle,STR(n,2)+"-> "+aDatos[n][1]+"|"+aDatos[n][2]+"|"+aDatos[n][3]+"|"+aDatos[n][4]+"|"+aDatos[n][5]+"|"+STR(aDatos[n][6],15,2)+CHR(13)+CHR(10))
    NEXT n
    FWRITE(nHandle,""+CHR(13)+CHR(10))

    aDatos:=ACLONE(aCopia)
    ASORT(aDatos,,,{ |x,y| (x[4]>y[4]).AND.(x[3]>y[3]).AND.(x[2]>y[2]).AND.(x[6]>y[6]) })

    FWRITE(nHandle,"sorted with { |x,y| (x[4]>y[4]).AND.(x[3]>y[3]).AND.(x[2]>y[2]).AND.(x[6]>y[6]) } [Ella's suggestion]"+CHR(13)+CHR(10))
    FOR n:=1 TO LEN(aDatos)
    FWRITE(nHandle,STR(n,2)+"-> "+aDatos[n][1]+"|"+aDatos[n][2]+"|"+aDatos[n][3]+"|"+aDatos[n][4]+"|"+aDatos[n][5]+"|"+STR(aDatos[n][6],15,2)+CHR(13)+CHR(10))
    NEXT n

    FCLOSE(nHandle)
    quit

    //--------------------------------------------------------------------

    original array
    TC|##|####|####|1,3| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00

    sorted with { |x,y| x[4]>y[4].AND.x[3]>y[3].AND.x[2]>y[2].AND.x[6]>y[6] }
    TC|##|####|####|1,3| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00

    sorted with { |x,y| x[4]+x[3]+x[2]+STR(x[6],15,2)>=y[4]+y[3]+y[2]+STR(y[6],15,2) }
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|####|1,3| 0.00

    sorted with { |x,y| (x[4]>y[4]).AND.(x[3]>y[3]).AND.(x[2]>y[2]).AND.(x[6]>y[6]) } [Ella's suggestion]
    TC|##|####|####|1,3| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Sat Sep 9 09:48:59 2023
    Il 09/09/2023 00:02, Claudio H ha scritto:

    Here a reduced self contained example and below the content of the log file generated.

    Thank you. Can you show me what is the output you want, please?

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Claudio H@21:1/5 to All on Mon Sep 11 09:11:45 2023
    Enrico

    This is the correct one:

    sorted with { |x,y| x[4]+x[3]+x[2]+STR(x[6],15,2)>=y[4]+y[3]+y[2]+STR(y[6],15,2) }
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|####|1,3| 0.00

    Thanks!
    Claudio H

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Mon Sep 11 21:12:28 2023
    Il 11/09/2023 18:11, Claudio H ha scritto:

    Enrico

    This is the correct one:

    sorted with { |x,y| x[4]+x[3]+x[2]+STR(x[6],15,2)>=y[4]+y[3]+y[2]+STR(y[6],15,2) }
    TC|##|####|1036|1,3,12| 0.00
    TC|VI|STDR|####|1,6| 0.00
    TC|##|####|####|1,3,6| 100000.00
    TC|##|####|####|1,3| 0.00

    Here it is:

    { | x, y | x[ 4 ] > y[ 4 ] .OR. ( x[ 4 ] = y[ 4 ] .AND. x[ 3 ] > y[ 3 ]
    ) .OR. ( x[ 3 ] = y[ 3 ] .AND. x[ 2 ] > y[ 2 ] ) .OR. ( x[ 2 ] = y[ 2 ]
    .AND. x[ 6 ] > y[ 6 ] ) }

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Thu Sep 14 14:06:37 2023
    Il 11/09/2023 21:12, Enrico Maria Giordano ha scritto:

    Here it is:

    { | x, y | x[ 4 ] > y[ 4 ] .OR. ( x[ 4 ] = y[ 4 ] .AND. x[ 3 ] > y[ 3 ]
    ) .OR. ( x[ 3 ] = y[ 3 ] .AND. x[ 2 ] > y[ 2 ] ) .OR. ( x[ 2 ] = y[ 2 ]
    .AND. x[ 6 ] > y[ 6 ] ) }

    Claudio, did you try it? Let me know if it works for you.

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From CV@21:1/5 to All on Thu Sep 14 11:46:49 2023
    El jueves, 14 de septiembre de 2023 a la(s) 09:06:39 UTC-3, Enrico Maria Giordano escribió:
    Il 11/09/2023 21:12, Enrico Maria Giordano ha scritto:

    Here it is:

    { | x, y | x[ 4 ] > y[ 4 ] .OR. ( x[ 4 ] = y[ 4 ] .AND. x[ 3 ] > y[ 3 ]
    ) .OR. ( x[ 3 ] = y[ 3 ] .AND. x[ 2 ] > y[ 2 ] ) .OR. ( x[ 2 ] = y[ 2 ] .AND. x[ 6 ] > y[ 6 ] ) }
    Claudio, did you try it? Let me know if it works for you.
    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    Hi Enrico

    I tested the snippet with your solution, and it works fine, but... it is noisy.

    Don't you think it is an error in the expression's evaluator inside the codeblock?

    I used many complex expressions in my code inside codeblocks and I never tried to run a verification like this one (for sure I trusted the compiler in the way: "it SHOULD work" - but it is not the case).

    Regards
    --
    Claudio Voskian
    Buenos Aires - Argentina

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Fri Sep 15 00:02:21 2023
    Il 14/09/2023 20:46, CV ha scritto:

    Don't you think it is an error in the expression's evaluator inside the codeblock?

    No, I don't think so.

    I used many complex expressions in my code inside codeblocks and I never tried to run a verification like this one (for sure I trusted the compiler in the way: "it SHOULD work" - but it is not the case).

    Are you referring to this codeblock?

    { | x, y | x[ 4 ] > y[ 4 ] .AND. x[ 3 ] > y[ 3 ] .AND. x[ 2 ] > y[ 2 ]
    .AND. x[ 6 ] > y[ 6 ] }

    If yes, it is just wrong. Please examine the expression carefully and
    you'll see yourself the problem.

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)