RE: compare() and equal()
- Posted by graemeburke at CROSSWINDS.NET Apr 09, 2001
- 504 views
>It returns zero or non-zero, and zero equates to false in a boolean compare. >Equal() returns 1 (true) or 0 (false) the same way, but the true-1 in equal() >and the true-0 in compare() feels too odd. > >Kat As Patrat mentioned, Rob included equal() because a number of people requested it to get rid of lots of : if not compare(a,b) then ..... lines. Which was the origional way of testing for identical sequences. If you use it as a boolean, then compare works perfectly as a test for inequality... i.e. if a!=b then ... if compare(a,b) then... vs. if a=b then .... if equal(a,b) then... When used in this fashion, compare will either return 1 or -1 (both of which equate to TRUE in Eu) if the sequences are diffrent, of 0 (FALSE) if they are equal. In fact the only reason equal() exists at all is because it was argued (successfully) that "not compare" was being used more frequently than just "compare". You can replace equal() with "not compare()", so long as the return value is not evaluated, which is uncommon. equal(a,b) _always_ equals abs(not compare(a,b)) Graeme