The Wayback Machine - https://web.archive.org/web/20240910091234/https://www.geeksforgeeks.org/introduction-to-lisp/
Open In App

Introduction to LISP

Last Updated : 17 Mar, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Lisp is a programming language that has an overall style that is organized around expressions and functions. Every Lisp procedure is a function, and when called, it returns a data object as its value. It is also commonly referred to as “functions” even though they may have side effects.

Lisp is the second-oldest high-level programming language in the world which is invented by John McCarthy in the year 1958 at the Massachusetts Institute of Technology.

Features of  LISP Programming Language:

  1. It is a machine-independent language
  2. It uses iterative design methodology and is easily extensible
  3. It allows us to create and update the programs and applications dynamically.
  4. It provides high-level debugging.
  5. It supports object-oriented programming.
  6. It supports all kinds of data types like objects, structures, lists, vectors, adjustable arrays, set, trees,hash-tables, and symbols.
  7. It is an expression-based language
  8. It can support different decision-making statements like if, when,case, and cond
  9. It will also support different iterating statements like do, loop,loopfor, dotimes and dolist.
  10. It will support input and output functions
  11. By using lisp we can also create our own functions

These are the features of LISP Programming.

Hello World program in LISP:

we can start writing  a string by using the write-line method

Syntax:

(write-line string)

Example:

Lisp




;this is a comment
(write-line "Hello Geeks")


Output:

Hello Geeks

Naming Conventions:

The naming Conventions mean the way we are declaring variables in a program. It includes the variable names and syntax formats

Lets us discuss the conventions

  • A variable can contain  any number of alphanumeric characters other than whitespace, open and  closing parentheses

Example:

Acceptable – hello,saisravan, etc

Not Acceptable – hell()0,sat{ sravab{,,,,,,,,etc

  • A variable can not contain double and single quotes, backslash, comma, colon, semicolon, and vertical bar.

Example:

Acceptable – hello,saisravan, etc

Not Acceptable – hell””)0,sat//*& sra//>vab{,,,,,,,,etc

  • A variable can not start with a digit but. it can contain any number of digits

Example:

Acceptable – hello88Geeks, r56lisp, ,,,,,etc

Not Acceptable – 40geeks,4klll,….etc

Example Code: For acceptable names

Lisp




;acceptable naming conventions
(write-line "hello")
 
(terpri)
 
;acceptable naming conventions
(write-line "hello99")
 
(terpri)
 
;acceptable naming conventions
(write-line "hello geeks")
 
(terpri)
 
;acceptable naming conventions
(write-line "hello_Geek")
 
(terpri)
 
;acceptable naming conventions
(write-line "hello123")


 Output:

hello
hello99
hello geeks
hello_Geek
hello123


Similar Reads

Constants in LISP
In LISP all constants are global variables. Values of constant never change throughout the execution of the program. Defining constant in LISP: New global constants are defined using the DEFCONSTANT construct Syntax: (defconstant name initial-value-form "documentation-string") Example: Let's create a global constant whose value will contain the rat
2 min read
Dotimes Construct in LISP
In this article, we will discuss the dotimes loop in LISP. The dotimes is a looping statement used to iterate the elements. Unlike other looping constructs, it only loops for a specified number of iterations. Syntax: (dotimes (n range) statements --------------- -------------- ) where, n is the starting number-0The range is the last number till tha
1 min read
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
3 min read
Logical Operators in LISP
Common LISP supports 3 types of logical operators on Boolean Values. The arguments of these operators are evaluated conditionally, therefore they are also part of the LISP control Structure. The common LISP operators are listed below in the table: OperatorSyntaxDescriptionandand number1 number2This operator takes two numbers which are evaluated lef
2 min read
Input & Output in LISP
Pre-requisites: Introduction to LISP Lisp provides a huge set of facilities for performing input/output. All the input/output operations are performed on streams of several kinds. While reading and writing binary data is possible, the majority of Common Lisp input/output methods read or write characters. For reading and writing individual character
10 min read
Keyword Parameters in LISP
LISP Function's parameters list has a basic aim of declaring the variables which will receive the arguments that are passed in the function. Normally parameter list contains a basic list of variable names, those parameters are called "required parameters". If a function is called, for every required parameter it should be supplied with one individu
3 min read
Basic Syntax 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. Basic Blocks in LISP:There are three basic building blocks of the LISP program: AtomListStringAtom: An atom in
2 min read
Program Structure in LISP
The expressions we use in Lisp are known as the s-expressions which are composed of atoms, strings, and lists. An s-expression is itself a valid program. REPL:REPL is an acronym for Read Evaluate Print Loop. In the case of an interpreter, the program is read, checked for errors in loops, and the value is returned by the program. Lisp program can ru
2 min read
Strings in LISP
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 C/C++ Code ;edisplay hello geek (write-line "Hello Geek") ;display (write-line "Welcome to java") Output: Hello Geek Welcome to javaString Comparison Functions: Used to compare
4 min read
Comparison Operators in LISP
In this article, we will discuss the comparison operators in LISP. These operators are used to compare numbers by taking two or more operands. Note: This will work only on numbers, Different comparison operators are:OperatorSyntaxNameDescription== operand1 operand2equal toThis operator checks if the values of the operands are all equal or not, if y
4 min read
Hash Table in LISP
A hash table is a type of collection in Common LISP, that is used to map keys to values. Any non-null object can be used as a key or as a value. To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method and the equals method. Types of Hash Tables in LISP: There are three types of hashta
3 min read
Arithmetic Operators in LISP
Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division. There are 7 arithmetic operators in LISP that are listed in the below table: OperatorSyntaxDescriptionAddition Operator(+)+ num1 num2Add the two numbersSubtraction Operator(-)- num1 num2Subtract the second number from the first
2 min read
Loop For Construct in LISP
The loop for construct in common LISP is used to iterate over an iterable, similar to the for loop in other programming languages. It can be used for the following: This is used to set up variables for iteration.It can be used for conditionally terminate the iteration.It can be used for operating on the iterated elements. The loop For construct can
2 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 cons cell with car and dir. car: It is used to acces
2 min read
Dolist Construct in LISP
DoList in Common LISP is a looping statement used to iterate the elements in a list. Syntax: (dolist input_list) statements... ) Here, The input_list contains the list of elements that are iterated.The statements are present in the loop. Example 1: LISP Program to iterate the list of elements from 1 to 5. C/C++ Code ;create a dolist of 1 to 5 eleme
2 min read
Loops in LISP
Loops allow executing a set of instructions repeatedly while some condition is true. LISP provides the following types of loops: 1. dotimes loop: The dotimes loop allows executing instructions for a fixed number of times.Syntax: (dotimes( variableName numberOfIterations ) ( expressions )) Where, variableName => Name of the variable, this can be
4 min read
Functions in LISP
A function is a set of statements that takes some input, performs some tasks, and produces the result. Through functions, we can split up a huge task into many smaller functions. They also help in avoiding the repetition of code as we can call the same function for different inputs. Defining Functions in LISP: Functions in LISP are defined using th
3 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 variables: Local variablesGlobal variablesLocal Variabl
3 min read
Optional Parameters in LISP
Optional Parameters are the parameters that are optional in the function. We can put optional parameters whenever the arguments are not necessary. If we keep the optional parameters in a function and pass the values, then the values are taken in place of optional parameters. If values are not passed, then optional parameters will take NIL and retur
2 min read
How to Install LISP on MacOS?
Lisp is one of the oldest programming languages. It was invented back in the 1950s by John McCarthy. Lisp is a so-called meta-programming language or a symbolic programming language. It can be used for any sort of task. It's a general-purpose language. It is the second-oldest high-level programming language. In this tutorial, we are going to see ho
1 min read
Macros in LISP
Macro is similar to a function in popular languages like C++, java, etc. that takes arguments and returns a LISP form to be evaluated. It is useful when the same code has to be executed with a few variable changes.For example, rather than writing the same code for squaring a number, we can define a macro that holds the code for squaring. Defining a
2 min read
Rest Parameters in LISP
LISP Function's parameters list has a basic aim of declaring the variables which will receive the arguments that are passed in the function. Normally parameter list contains a basic list of variable names, those parameters are called "required parameters". If a function is called, for every required parameter it should be supplied with one individu
3 min read
Returning Values Functions in LISP
In the previous article on the LISP function, we have seen the syntax of defining a function and calling the function by passing some arguments. Returning values from a function: In LISP, whatever is the last expression in the body of a function becomes the return value of that function. Example: Let's create a function that takes the input paramet
2 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 say that an operator operates the operands. Differ
5 min read
Bitwise Operators in LISP
In this article, we will discuss the Bitwise operators in LISP. These operators are used to perform the manipulation of individual bits of a number. The truth table for bitwise AND, NAND, OR, XOR, NOR, & XNOR: aba and b a nand ba or b a xor b a nor b a xnor b00010011010111001110100110011100 Different bitwise operators in LISP are listed below i
4 min read
Cond Construct in LISP
In this article, we will discuss cond construct in LISP. The cond is a decision-making statement used to make n number of test conditions. It will check all the conditions. Syntax: (cond (condition1 statements) (condition2 statements) (condition3 statements) ... (conditionn statements) ) Here, The conditions specify different conditions - if condit
2 min read
If Construct in LISP
In this article, we will discuss the if construct in LISP. The if is a decision-making statement used to check whether the condition is right or wrong. The if the condition is right, then it will go inside the if block and execute the statements under if block. Otherwise, the statements are not executed. Syntax: (if (condition) then (statement 1)..
2 min read
Do Construct in LISP
In this article, we will discuss the Do Construct in LISP. Do construct is used to perform an iteration in a structured format. Syntax: (do ((variable1 value1 new updated value 1) (variable2 value2 new updated value 2) ------------------------------- ------------------------------- (variable n value n new updated value n) ...) (test statements) ) H
2 min read
Lambda Functions in LISP
In this article, we will discuss lambda functions in LISP. The Lambda function is used to evaluate a mathematical expression in our program. They are also known as anonymous functions. We can create these functions using lambda expression. Syntax: (lambda (parameters) expression_code) where, The parameters are the numbers of operands in the express
1 min read
When Construct in LISP
In this article, we will discuss the when construct. The when is a decision-making statement used to specify the decisions. It is similar to conditional statements. Syntax: (when (condition) (statements) ) where, condition is a test statement used to teststatements are the actions that will depend on the condition Example 1: LISP Program to check t
2 min read
Article Tags :