MAINSAIL Language Manual, Section 32.44

previous   next   top   contents   index   framed top   this page unframed


32.44. compare

Figure 32–45. compare
INTEGER
PROCEDURE   compare     (STRING r,s;
                         
OPTIONAL BITS ctrlBits);

compare returns an INTEGER that represents the comparison of r and s.

compare returns -1 if r is less than s, 0 if r is equal to s, or 1 if r is greater than s. STRING comparison is discussed in Section 4.8.2.

A single valid BITS constant, upperCase, may be set in ctrlBits. If set, it means to ignore distinctions between upper- and lowercase letters in the STRINGs when doing the comparison. compare(r,s,upperCase) returns the same value as compare(cvu(r),cvu(s)) but is more efficient.

In Example 32–46, the first form is more efficient since only a single comparison takes place. In the second form two implicit calls to compare are generated, one for < and one for =.

Example 32–46. Use of compare
CASE compare(r,sOFB [-1] s1; [0] s2; [1] s3 END

is equivalent to:

IF r < s THEN s1
EF r = s THEN s2
EL s3

A garbage collection cannot occur during a call to compare.


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Language Manual, Section 32.44