Bug in Harbour Descend()

Bug in Harbour Descend()

Postby Enrico Maria Giordano » Mon Apr 12, 2021 1:15 pm

This is a sample of the problem:

Code: Select all  Expand view
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 view
TEST1       3107.77
TEST2        852.07
TEST5         44.73
TEST6         15.24
TEST7        255.65
TEST4        148.68
TEST3        191.00


Any workaround?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bug in Harbour Descend()

Postby hmpaquito » Mon Apr 12, 2021 2:10 pm

IMHO Test is erronous

Sorting so:

Code: Select all  Expand view
ASORT( aData, , , { | aItem1, aItem2 | Descend( Str( aItem1[ 2 ], 10, 2 )  + aItem1[ 1 ] ) < Descend( Str( aItem2[ 2 ], 10, 2 )  + aItem2[ 1 ]  )} )


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

Re: Bug in Harbour Descend()

Postby Enrico Maria Giordano » Mon Apr 12, 2021 2:57 pm

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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bug in Harbour Descend()

Postby Enrico Maria Giordano » Mon Apr 12, 2021 3:14 pm

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
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bug in Harbour Descend()

Postby nageswaragunupudi » Mon Apr 12, 2021 9:44 pm

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 view

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
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Bug in Harbour Descend()

Postby Enrico Maria Giordano » Tue Apr 13, 2021 7:33 am

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: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Re: Bug in Harbour Descend()

Postby Enrico Maria Giordano » Tue Apr 13, 2021 9:37 am

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bug in Harbour Descend()

Postby AntoninoP » Tue Apr 13, 2021 3:28 pm

have you tryied using StrZero instead of Str?
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Bug in Harbour Descend()

Postby Enrico Maria Giordano » Tue Apr 13, 2021 4:42 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bug in Harbour Descend()

Postby hmpaquito » Tue Apr 13, 2021 4:59 pm

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

Re: Bug in Harbour Descend()

Postby AntoninoP » Tue Apr 13, 2021 8:53 pm

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 view

    ? chr(199)<chr(205) //--> T
    HB_SETCODEPAGE( "ITWIN" )
    ? chr(199)<chr(205) //--> F
 

the problem is not the descend... very sad
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Bug in Harbour Descend()

Postby Enrico Maria Giordano » Mon Oct 17, 2022 11:07 am

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
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Bug in Harbour Descend()

Postby karinha » Mon Oct 17, 2022 1:33 pm

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
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Bug in Harbour Descend()

Postby Enrico Maria Giordano » Mon Oct 17, 2022 2:12 pm

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.
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 86 guests