Page 1 of 3
Bug in Harbour Descend()
Posted: Mon Apr 12, 2021 1:15 pm
by Enrico Maria Giordano
This is a sample of the problem:
Code: Select all | Expand
REQUEST HB_CODEPAGE_ITWIN
FUNCTION MAIN()
LOCAL aData[ 7 ]
LOCAL i
HB_SETCODEPAGE( "ITWIN" )
aData[ 1 ] = { "TEST1", 3107.77 }
aData[ 2 ] = { "TEST2", 852.07 }
aData[ 3 ] = { "TEST3", 191.00 }
aData[ 4 ] = { "TEST4", 148.68 }
aData[ 5 ] = { "TEST5", 44.73 }
aData[ 6 ] = { "TEST6", 15.24 }
aData[ 7 ] = { "TEST7", 255.65 }
ASORT( aData, , , { | aItem1, aItem2 | Descend( Str( aItem1[ 2 ], 10, 2 ) ) + aItem1[ 1 ] < Descend( Str( aItem2[ 2 ], 10, 2 ) ) + aItem2[ 1 ] } )
FOR i = 1 TO LEN( aData )
? aData[ i, 1 ], aData[ i, 2 ]
NEXT
INKEY( 0 )
RETURN NIL
Result:
Code: Select all | Expand
TEST1 3107.77
TEST2 852.07
TEST5 44.73
TEST6 15.24
TEST7 255.65
TEST4 148.68
TEST3 191.00
Any workaround?
EMG
Re: Bug in Harbour Descend()
Posted: Mon Apr 12, 2021 2:10 pm
by hmpaquito
IMHO Test is erronous
Sorting so:
Code: Select all | Expand
ASORT( aData, , , { | aItem1, aItem2 | Descend( Str( aItem1[ 2 ], 10, 2 ) + aItem1[ 1 ] ) < Descend( Str( aItem2[ 2 ], 10, 2 ) + aItem2[ 1 ] )} )
Regards
Re: Bug in Harbour Descend()
Posted: Mon Apr 12, 2021 2:57 pm
by Enrico Maria Giordano
No, as I want to sort for the second item descending and the first item ascending. Anyway, it doesn't work either.
EMG
Re: Bug in Harbour Descend()
Posted: Mon Apr 12, 2021 3:14 pm
by Enrico Maria Giordano
The problem seems to be the codepage. Without setting it, the sort order is correct. But the codepage should not affect the behaviour of Descend() function, should it?
EMG
Re: Bug in Harbour Descend()
Posted: Mon Apr 12, 2021 9:44 pm
by nageswaragunupudi
I am not commenting on the behaviour of the Descend() function, but I would have approached it in a different way:
Code: Select all | Expand
ASort( aData,nil,nil, { |x,y| If( x[ 2 ] == y[ 2 ], x[ 1 ] > y[ 1 ], x[ 2 ] > y[ 2 ] ) } )
Re: Bug in Harbour Descend()
Posted: Tue Apr 13, 2021 7:33 am
by Enrico Maria Giordano
Thank you. It is not feasible as it would require to change all the ASort() calls. I prefer to remove the codepage.
EMG
Re: Bug in Harbour Descend()
Posted: Tue Apr 13, 2021 9:17 am
by hmpaquito
Re: Bug in Harbour Descend()
Posted: Tue Apr 13, 2021 9:37 am
by Enrico Maria Giordano
It looks like the bug has never been fixed.

EMG
Re: Bug in Harbour Descend()
Posted: Tue Apr 13, 2021 3:28 pm
by AntoninoP
have you tryied using StrZero instead of Str?
Re: Bug in Harbour Descend()
Posted: Tue Apr 13, 2021 4:42 pm
by Enrico Maria Giordano
Yes, the order changes but it's not correct either.
EMG
Re: Bug in Harbour Descend()
Posted: Tue Apr 13, 2021 4:59 pm
by hmpaquito
The purpose of Descend () is to be Clipper compatible. Therefore it is not an error, but an unexpected behavior for those who use codepages
The existence of hb_Descend (), compatible with the codepage system, would be highly desirable.
Re: Bug in Harbour Descend()
Posted: Tue Apr 13, 2021 8:53 pm
by AntoninoP
I see that if you remove HB_SETCODEPAGE from your example the array looks correctly sorted...
I investigated a little and I found that there is a flag in the code pages "BinarySort" that indicate if the comparison can be simply binary or more complex, it is true for "en" and false for "itwin"
Try this:
Code: Select all | Expand
? chr(199)<chr(205) //--> T
HB_SETCODEPAGE( "ITWIN" )
? chr(199)<chr(205) //--> F
the problem is not the descend... very sad
Re: Bug in Harbour Descend()
Posted: Mon Oct 17, 2022 11:07 am
by Enrico Maria Giordano
How do you deal with this bug? I need to use codepage with Harbour, otherwise the accented chars are not correctly read from the file system (ie. filenames, Directory(), File(), Memoread(), etc.). But doing so, Descend() function is not working anymore. I can't even build index with Descend() in the key. Any help, please.
Re: Bug in Harbour Descend()
Posted: Mon Oct 17, 2022 1:33 pm
by karinha
Master Enrico, see if it helps:
https://linguagemclipper.com.br/dicas/arraysRegards, saludos.
Re: Bug in Harbour Descend()
Posted: Mon Oct 17, 2022 2:12 pm
by Enrico Maria Giordano
Thank you, but I can't found anything about Descend() function in that web page. I need to use Descend() in Harbour just like I use it in xHarbour and used in Clipper. Please look at my first message on this thread for a sample of the problem.