previous contents index next
(Operators..) Contents Index (..Operators..)

2.7.1 Relational Operators (RelOp)

SCARLET provides all the common relational operators on integer expressions IntExpression in just the form we are used to in daily life. In detail we are talking about

RelOp:
== equal to
< less than
> greater than
!= not equal to
>= greater than or equal to
<= less than or equal to

They compare two operands at a time and return a boolean value corresponding to the resulting logical value.


 

But relational operators may also be applied to string expressions (short: strings) StringExpression. In this case, the normal comparison for numbers is replaced by the lexical one, that means, two strings are compared character by character, starting at the left and obeying the following rules:

If the exceptional features of the internal order of the ASCII code are not taken in account, the lexical comparison may sometimes lead to slightly surprising results:


Example 8:

 "bigger" > "big"     leadsto  TRUE
 "mouse" > "MAMMOTHE" leadsto  TRUE
 "99" > "One"         leadsto  FALSE

 

Parts of the ASCII code
21§ 45- 65A 124|
33! 46. .... 125}
34" 47/ 90Z 126~
35# 480 91[ 129ü
36$ .... 92\ 132ä
37% 579 93] 142Ä
38& 58: 94^ 148ö
39' 59; 95_ 153Ö
40( 60< 96` 154Ü
41) 61= 97a 248°
42* 62> .... 255 
43+ 63? 122z   
44, 64@ 123{   



 

Because cell expressions CellExpression consist of one or more registers with the same priority, it does not normally make sense to ask whether one cell expression is greater (or less) than the other; but some of the relational operators can successfully be applied to them, too, namely == (equal) and != (not equal). Here a comparison can be done by comparing all corresponding registers with each other. Hence two cell expressions are equal, if the contents of each corresponding register pair are equal; otherwise they are not equal. Doing this, we take for granted that both cell expressions have the same register structure, otherwise they would not be comparable. (In fact this cannot happen, since the structure is uniformly fixed for all cell expressions within one program.)

If it is the issue, whether two register contents are equal while one of them is VOID, the result will always be TRUE; (in case of "unequal" it will be FALSE.) Indeed VOID enables partial comparisons of cell expressions.


Example 9:

 {"s", 25, VOID} == {"s", 25, "a"}    leadsto  TRUE
 {"s", 25, VOID} != {"s", 25, "a"}    leadsto  FALSE

previous contents index next
(Operators..) Contents Index (..Operators..)