Comparison Operators on Character

Characters are not supported by numerical comparison functions and operators such as < and >. Other than that, Two sets of functions in Common LISP are used. The first set is case-sensitive, whereas the second is not case-sensitive or (case-insensitive). 

Following are some comparison functions that may be used to see whether the two characters are equivalent or not equal.

Case-Sensitive Case-Insensitive Explanation
CHAR=  CHAR-EQUAL Checks if the operands’ values are all equal; if they are, the condition is true.
CHAR/= CHAR-NOT-EQUAL Checks if the operands’ values are all different or not; if they aren’t, the condition is true.
CHAR< CHAR-LESSP If the character1 is smaller than character2, the condition is true; otherwise, the condition is false.
CHAR<= CHAR-NOT-GREATERP If any of the left character’s values are less than or equal to the value of the following right character, the condition is true.
CHAR> CHAR-GREATERP If character1 is greater than character2, the condition is true; otherwise, it is false.
CHAR>=                      CHAR-NOT-LESSP                                   If any left character’s value is more than or equal to its right character’s value, the condition is true.

Example 1: Case sensitive Comparison

Lisp




(write (CHAR= #\a #\A))
(terpri)
(write (CHAR> #\b #\a))
(terpri)
(write (CHAR< #\A #\a))


Output: When running the above code, the output is as follows.

NIL
T
T

Example 2: Case-insensitive Comparison

Lisp




(write (CHAR-EQUAL #\a #\A))
(terpri)
(write (CHAR-EQUAL #\a #\b))
(terpri)
(write (CHAR-LESSP #\a #\b #\c))
(terpri)
(write (CHAR-GREATERP #\a #\b #\c))


Output: When running the above code, the output is as follows.

T
NIL
T
NIL

LISP – Comparison Operators on Characters & Strings

The contents of a field are compared to the contents of another field or a constant using Comparison operators. In Simple words, comparator operators are used to compare whether the two or more different values are equal or not. 

Similar Reads

Comparison Operators on Character:

Characters are not supported by numerical comparison functions and operators such as < and >. Other than that, Two sets of functions in Common LISP are used. The first set is case-sensitive, whereas the second is not case-sensitive or (case-insensitive)....

Comparison Operators on String:

...