Open In App

Strings in LISP

Last Updated : 30 Sep, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

A string is a set of characters. String  are enclosed in double-quotes. 

Example:

"hello geek","java","python" etc

Example: LISP program to display strings

Lisp
;edisplay hello geek
(write-line "Hello Geek")

;display 
(write-line "Welcome to java")

Output:

Hello Geek
Welcome to java

String Comparison Functions:

Used to compare two strings. Further they can be divided into two categories. They are

Case Sensitive Functions:

These functions can be represented by mathematical symbols.

SymbolNameSyntaxDescription
=equal tostring=This operator checks if the values of the operands are all equal or not, if yes then the condition becomes true(T). otherwise it returns NIL
/=not equal tostring/=This operator checks if the values of the operands are all different or not, if values are not equal then the condition becomes true(T). otherwise, it returns NIL
>greater thanstring>This operator checks if the values of the operands are monotonically increasing.
<less thanstring<This operator checks if the values of the operands are monotonically decreasing.
>=greater than or equal tostring>=This operator checks if the value of any left operand is less than or equal to the value of its right operand, if yes then the condition becomes true.
<=less than or equal tostring<=This operator checks if the value of any left operand is greater than or equal to the value of the next right operand, if yes then the condition becomes true.

Example: LISP program that demonstrates string case sensitive functions

Lisp
; case-sensitive comparison - equal to 
(write (string= "Hello Geeks" "Hello Geeks"))

;new line
(terpri)

; case-sensitive comparison - equal to 
(write (string= "Hello Geeks" "HelloGeeks"))

;new line
(terpri)

; case-sensitive comparison - not equal to 
(write (string/= "Hello Geeks" "Hello Geeks"))

;new line
(terpri)

; case-sensitive comparison - not equal to 
(write (string/= "Hello Geeks" "HelloGeeks"))

;new line
(terpri)

; case-sensitive comparison -  greater than
(write (string> "Hello Geeks" "Python"))

;new line
(terpri)

; case-sensitive comparison -  less than
(write (string< "Hello Geeks" "java"))

;new line
(terpri)

; case-sensitive comparison -  greater than or equal to
(write (string>= "Hello Geeks" "Python"))

;new line
(terpri)

; case-sensitive comparison -  less than or equal to
(write (string<= "Hello Geeks" "java"))

;new line
(terpri)

Output:

T
NIL
NIL
5
NIL
0
NIL
0

Case INSENSITIVE FUNCTIONS

These functions can be represented by expressions.

NameSyntaxDescription
equalstring-equalThis operator checks if the values of the operands are all equal or not, if yes then the condition becomes true(T). Otherwise, it returns NIL
not equalstring-not-equal This operator checks if the values of the operands are all different or not, if values are not equal then the condition becomes true(T). Else, it returns NIL
greater thanstring-greaterp This operator checks if the values of the operands are monotonically increasing.
less thanstring-lessp This operator checks if the values of the operands are monotonically decreasing.
greater than or equal tostring-not-lessp This operator checks if the value of any left operand is less than or equal to the value of its right operand, if yes then the condition becomes true.
less than or equal tostring-not-greaterp This operator checks if the value of any left operand is greater than or equal to the value of the next right operand, if yes then the condition becomes true.

Example: Lisp program that demonstrates case insensitive functions

Lisp
; case-sensitive comparison - equal to 
(write (string-equal "Hello Geeks" "Hello Geeks"))

;new line
(terpri)

; case-sensitive comparison - equal to 
(write (string-equal "Hello Geeks" "HelloGeeks"))

;new line
(terpri)

; case-sensitive comparison - not equal to 
(write (string-not-equal "Hello Geeks" "Hello Geeks"))

;new line
(terpri)

; case-sensitive comparison - not equal to 
(write (string-not-equal "Hello Geeks" "HelloGeeks"))

;new line
(terpri)

; case-sensitive comparison -  greater than
(write (string-greaterp "Hello Geeks" "Python"))

;new line
(terpri)

; case-sensitive comparison -  less than
(write (string-lessp "Hello Geeks" "java"))

;new line
(terpri)

; case-sensitive comparison -  greater than or equal to
(write (string-not-lessp "Hello Geeks" "Python"))

;new line
(terpri)

; case-sensitive comparison -  less than or equal to
(write (string-not-greaterp "Hello Geeks" "java"))

;new line
(terpri)

Output:

T
NIL
NIL
5
NIL
0
NIL
0

Next Article
Article Tags :

Similar Reads