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.
Symbol | Name | Syntax | Description |
---|
= | equal to | string= | 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 to | string/= | 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 than | string> | This operator checks if the values of the operands are monotonically increasing. |
---|
< | less than | string< | This operator checks if the values of the operands are monotonically decreasing. |
---|
>= | greater than or equal to | string>= | 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 to | string<= | 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.
Name | Syntax | Description |
---|
equal | string-equal | 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 | string-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 than | string-greaterp | This operator checks if the values of the operands are monotonically increasing. |
---|
less than | string-lessp | This operator checks if the values of the operands are monotonically decreasing. |
---|
greater than or equal to | string-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 to | string-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
Similar Reads
Sets in LISP A set is an unordered collection of items. A set is just like other data structures. In C++ we have a similar data structure called a hash map. Common lisp does not provide a built-in set data type, but it provides a number of functions that allow set operations to be performed onto a list. Using th
7 min read
Lists in LISP Lists in common LISP is simply a single Linked list. In LISP, Lists are designed as a chain of records. While talking about record structures in LISP, the concept of Cons is vital. Cons in LISP is a record structure with 2 Â primary components. A cons function takes in 2 arguments and returns a new c
2 min read
Structures in LISP LISP, is a list processing, is a programming language widely used in working with data manipulation. Structures are used defines data types, that have the ability to combine with another data type to complete the given task. Attribute used: The defstruct attribute is used to create an instance of a
2 min read
Vectors in LISP In this article, we will discuss Vectors in LISP. Vectors in LISP are one-dimensional arrays which are also known as sequences. We can create a vector using vector function and # symbol Syntax: variable_name(vector element1 element2 ... element n) or variable_name #(element1 element2 ... element n)
2 min read
String find() in C++ In C++, string find() is a built-in library function used to find the first occurrence of a substring in the given string. Letâs take a look at a simple example that shows the how to use this function:C++#include <bits/stdc++.h> using namespace std; int main() { string s = "Welcome to GfG!"; s
4 min read
Sequences in LISP In Lisp, the ordered set of elements is represented by sequences. All the functionality we use in sequences is applied on vectors and lists which are two of the subtypes of sequences. Creating a Sequence:The generic function for creating a Sequence in Lisp is: ;The generic function for creating a Se
7 min read
PL/SQL Strings We will learn several types of strings, the syntax for declaring a string variable, and then utilizing it in a PL/SQL code block. In PL/SQL, a string is a sequence of characters with an optimal size parameter. Strings are sequences of characters, and PL/SQL provides a rich set of functions and opera
6 min read
Operators in LISP Operators are the foundation of any programming language. Thus the functionality of the LISP programming language is incomplete without the use of operators. We can define operators as symbols that help us to perform specific mathematical and logical computations on operands. In other words, we can
5 min read
Variables in LISP Similar to other languages, in LISP variables are named places that store a particular value, but they are not declared the way you declare variables in C++ or Java i.e you don't need to mention data-type of variables when declaring them as LISP is dynamically typed. LISP supports two types of varia
3 min read
Numbers in LISP LISP is a list processing programming language. It is widely used in the manipulation of data strings. It provides an input and output library. LISP provides a macro system and provides well control structures for the manipulation of data. LISP Math Function:floor:Â floor returns the nearest smalles
2 min read