SIMPOL Documentation

Comparison Operators

The list of comparison operators consists of symbols that should be familiar to most programmers, regardless of whether they are C or BASIC oriented. The operators currently supported are:

  • Equal to (==)

  • Greater than or equal to (>=)

  • Less than or equal (<=)

  • Not equal to (!= and <>)

  • Greater than (>)

  • Less than (<)

The == symbol, although familiar to Java, C, and C++ programmers is a bit of a new experience for BASIC programmers. Consider this symbol to be merely an unambiguous method of separating assignment from comparison. There are also two different symbols for not equal to, one used commonly in Java, C, and C++ and one found commonly in BASIC-oriented languages.

The set of operators in the previous paragraph are meant to be used with value types. For comparing object types, there is a different, more limited set of operators. This is mainly because object types are more complicated and must be compared in different ways and also because object types can have a value associated with them. As an example, date types where the value of the object is an integer equal to the total number of days in the date since Jauary 1, 0001. This feature of the language required a different set of operators to be established for the comparison of object types, again to be unambiguous. These operators are listed below:

  • Refers to the same object (=@=)

  • Does not refer to the same object (!@= and <@>)

In some languages, such as in SBL, there is a function to perform the comparison of two object variables. In SBL this is done with the IS() function. In keeping with the decision to try and limit the number of keywords in the language, it was decided to use operators for this purpose rather than add keywords. It is important to understand the difference between these operators and the ones used for comparing values. Look at the following example:

function main()
  string s1, s2, sResult

  s1 = "foo"
  s2 = "foo"

  if s1 == s2
    sResult = "They are equal in value"
  else
    sResult = "They are not equal in value"
  end if

  if s1 =@= s2
    sResult = sResult + " and they refer to the same object."
  else
    sResult = sResult + " and they refer to different objects."
  end if
end function sResult

When this program is run it will output as its result, They are equal in value and they refer to different objects. It is also possible to have a string variable refer to the same object as another string variable. In that case, any change to the value of the first variable will also change the value for the second since they both refer to the same object. See the example shown below:

function main()
  string s1, s2, sResult

  s1 = "foo"
  s2 =@ s1

  s1 = "foobar"

  if s1 == s2
    sResult = "They are equal in value"
  else
    sResult = "They are not equal in value"
  end if

  if s1 =@= s2
    sResult = sResult + " and they refer to the same object."
  else
    sResult = sResult + " and they refer to different objects."
  end if
end function sResult

When this program is run it will result in the output, They are equal in value and they refer to the same object.