Bug in Harbour Descend()

User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Bug in Harbour Descend()

Post 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
hmpaquito
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Bug in Harbour Descend()

Post 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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: Bug in Harbour Descend()

Post 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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: Bug in Harbour Descend()

Post 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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Bug in Harbour Descend()

Post 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 ] ) } )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: Bug in Harbour Descend()

Post 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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: Bug in Harbour Descend()

Post by Enrico Maria Giordano »

It looks like the bug has never been fixed. :-(

EMG
AntoninoP
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Bug in Harbour Descend()

Post by AntoninoP »

have you tryied using StrZero instead of Str?
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: Bug in Harbour Descend()

Post by Enrico Maria Giordano »

Yes, the order changes but it's not correct either.

EMG
hmpaquito
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Bug in Harbour Descend()

Post 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.
AntoninoP
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: Bug in Harbour Descend()

Post 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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: Bug in Harbour Descend()

Post 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.
User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by karinha »

Master Enrico, see if it helps:

https://linguagemclipper.com.br/dicas/arrays

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: Bug in Harbour Descend()

Post 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.
Post Reply