GeeksforGeeks App
Open App
Browser
Continue

# 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.

## 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.

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```

## Comparison Operators on String:

In Common Lisp, strings are vectors, which are one-dimensional arrays of characters. Except for the double quotation character (“) and the escape character (\), every character supported by the character set can be contained between double quotes to form a string. Like Character, the string also has two sets of Comparison Operators, one is Case-sensitive and the other is Case-insensitive.

So, to check whether the two Strings are equal are not, the following are some comparison Functions that can be used.

Example 1: Case Sensitive Comparison.

## Lisp

 `(write (STRING``=` `"gfg"` `"GFG"``))``(terpri)``(write (STRING> ``"gfg"` `"GFG"``))``(terpri)``(write (STRING< ``"gfg"` `"GFG"``))`

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

```NIL
0
NIL```

Example 2: Case-insensitive Comparison.

## Lisp

 `(write (STRING``-``EQUAL ``"gfg"` `"GFG"``))``(terpri)``(write (STRING``-``GREATERP ``"gfg"` `"GFG"``))``(terpri)``(write (STRING``-``LESSP ``"gfg"` `"GFG"``))`

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

```T
NIL
NIL```

My Personal Notes arrow_drop_up