Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 7, 2021 2:36:15 GMT -5
Hi
There appears to be a possible bug when you compare two ASCII values. I use the concept of high values (ASCII 255) in merging and sorting. It all works well until “z” is one of the values – “z” sorts as greater than chr$(255).
I may be wrong or I don’t know enough about Liberty Basic but try the following code snippet. It would appear that “z” is the highest value in Liberty Basic.
Any comment
a$ = chr$(255)
z$ = "z"
print a$,z$
print asc(a$), asc(z$)
if a$ > z$ then print "greater"
if a$ < z$ then print "lesser"
a$ = chr$(123)
print a$,z$
print asc(a$), asc(z$)
if a$ > z$ then print "greater"
if a$ < z$ then print "lesser"
a$ = chr$(121)
print a$,z$
print asc(a$), asc(z$)
if a$ > z$ then print "greater"
if a$ < z$ then print "lesser"
a$ = chr$(122)
print asc(a$), asc(z$)
if a$ > z$ then print "greater"
if a$ < z$ then print "lesser"
if a$ = z$ then print "equal"
end
|
|
|
Post by tsh73 on Aug 7, 2021 3:24:52 GMT -5
Not a bug but feature alycesrestaurant.com/lbpe/FastFAQ.htmlYou really need to be aware of it. So run this and try make sense of it. (and id depends on locale too - I've seen example where 't' got sorted after 'z') dim a$(255, 2) for i = 0 to 255 a$(i,1)=chr$(i) a$(i,2)="code ";i if i>31 then a$(i,2)=a$(i,2)+" char "+chr$(i) else a$(i,2)=a$(i,2)+" (unprintable) " end if next
'for i =0 to 255 ' print a$(i,1), a$(i,2) 'next 'print
sort a$(),0,255,1
for i =0 to 255 print a$(i,1), a$(i,2) next print
BTW for my locale chr$(255) sorts as greatest (last).
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 7, 2021 8:07:47 GMT -5
Hi Thanks for the response - sort of makes sense but concerning. I will need to change quite a few programs which have been successfully running under other BASICs for over 20 years. What concerned me is your comment that "t" can get sorted after "z". What then should one use as a "high-value" that will sort to the end of a table? If the sequence is "unpredictable" then I really have problems. I am not too sure what you mean by locale? I had this problem when I was in South Africa. I am now experiencing the same issue here in Greece. I have set my "region" from South Africa to Greece. Regards
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 7, 2021 8:22:34 GMT -5
Ok got it... I commented out the sort and printed the table. I will have to make some major modifications to my programs to cater for a different "high-value" Thanks for your help :-) :-)
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 7, 2021 8:37:20 GMT -5
HaHa. changed the print to lprint so now I have a reference table. Looking at the printed list jogged my ancient memory back to the days of GWBasic and QBasic some 35 years ago. I had got used to using ASCII lately and forgot that some BASICs do not use ASCII codes. All sorted now. I will use the printed reference table to sort out my tables, sorting, etc. I am getting old....
|
|
|
Post by Rod on Aug 7, 2021 11:22:26 GMT -5
Yes Liberty does not sort on asc() value, it sorts on the weight of the character the asc() value represents. The weighting is alphabetic order indeed more specifically dictionary order. In dictionary order the character A is sorted ahead of character a, capitals infer higher significance. This is bog standard library, dictionary, lexographic sorting.
Where does Liberty get its weighting? Therein lies the “locale” problem because Liberty uses one standard table that does not always reflect the weighting in your locale.
But it is a small problem, main alpha numeric sorting is easily handled by upper() or lower()
Locale issues can be handled by substitution but we would need someone with a locale issue to give us an example or clarification.
|
|
Dennis
Full Member
Old but still active
Posts: 147
|
Post by Dennis on Aug 7, 2021 23:16:29 GMT -5
Thanks Rod and Anatoly - I think I have it sorted now (no pun intended) :-) :-) I am looking at all my existing programs which use ASCII. I am also armed with the table I printed. Regards Dennis
|
|