SlideShare a Scribd company logo
1 of 35
PRESENTATION OF
ARTIFICIAL
INTELLIGENCE
TOPIC TO BE DISCUSSED
An INTRODUCTION OF LISP ?
FEATUERS OF LISP
TEXT EDITOR
LISP EXECUTOR
LISP – BASIC SYNTAX
LISP-DATA TYPES
LISP CONSTANT
LISP VARIABLES
LISP OPERATOR
DECISION MAKING
LISP ARRAY
LISP LOOP
AN INTRODUCTION OF LISP ?
•Lisp – List Processing language
• John McCarthy invented LISP in 1958, shortly after the development of
FORTRAN. It was first implement by Steve Russell on an IBM 704 computer
• It is one of the most popular language for Artificial Intelligence programs
• FEATURES OF LISP:
• It is machine-independent
• It allows updating the programs dynamically.
• It provides high level debugging.
FEATUERS OF LISP
• It provides wide-ranging data types like, objects, structures, lists, vectors, adjustable
arrays, hash-tables, and symbols.
• It provides an object-oriented condition system.
• It provides complete I/O library.
• It provides extensive control structures.
• Lisp was originally created as a practical mathematical notation for computer programs
USES OF COMMON LISP
USES OF CL
• CL is a very successful language in that
it is extremely powerful as an AI tool
those that use it love it
• And yet CL is a very uncommon language because
it is very complicated
most software development is in C++ (with some in Java, C#, C, Python, Ada, etc)
such that few programmers would choose to use CL for development
• The most important software developed from CL includes:
– Emacs
– G2 (a real-time expert system)
– AutoCAD
– Igor Engraver (musical notation editor and publisher)
– Yahoo Store
TEXT EDITOR
• This will be used to type your program. Examples of few editors include Windows
Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
• Name and version of text editor can vary on different operating systems. For example,
Notepad will be used on Windows, and vim or vi can be used on windows as well as
Linux or UNIX.
• The files you create with your editor are called source files and contain program source
code. The source files for Lisp programs are typically named with the extension ".lisp".
• Before starting your programming, make sure you have one text editor in place and
you have enough experience to write a computer program, save it in a file, finally
execute it.
TEXT EDITOR
• The source code written in source file is the human readable source for your program.
It needs to be "executed", to turn into machine language so that your CPU can actually
execute the program as per instructions given.
• This Lisp programming language will be used to execute your source code into final
executable program. I assume you have basic knowledge about a programming
language.
• CLISP is the GNU Common LISP multi-architechtural compiler used for setting up
LISP in Windows.
LISP EXECUTOR
LISP - BASIC SYNTAX
LISP programs are made up of three basic building blocks:
• atom
• list
• string
ATOM:
An atom is a number or string of contiguous characters. It includes numbers and special
characters.
LISP BASIC SYNTAX
EXAMPLE:
Name
2343333
*HELLO*
3333309
abc123
DEFINE LIST
LIST
A list is a sequence of atoms and/or other lists enclosed in parentheses
EXAMPLE
(I AM A GENIOUS GIRL)
(I AM A LIST)
(A(A B C)D )
DEFINE STRING
STRING
A string is a group of characters enclosed in double quotation marks
EXAMPLE
“I AM A STRING”
“ HELLO WORLD”
“PLEASE ENTER THE FOLLOWING DETAILS”
ADDING COMMENTS
COMMENTS
The semicolon symbol (;) is used for indicating a comment line
EXAMPLES
“I AM A STRING”
; HELLO WORLD
“PLEASE ENTER THE FOLLOWING DETAILS”
CONCEPTS ABOUT LISP
Following are some of the important points to note
The basic numeric operations in LISP are +, -, *, and /
LISP expressions are case-insensitive
Naming Conventions in LISP
• Name or symbols can consist of any number of alphanumeric characters other than
whitespace, open and closing parentheses, double and single quotes, backslash, comma,
colon, semicolon and vertical bar. To use these characters in a name, you need to use
escape character ().
• A name can have digits but not entirely made of digits, because then it would be read as a
number. Similarly a name can have periods, but can't be made entirely of periods.
LISP DATA TYPES
LISP data types can be categorized as
• Scalar types - for example, number types, characters, symbols etc.
• Data structures - for example, lists, vectors, bit-vectors, and strings.
LISP VARIABLES
Global Variables
• Global variables have permanent values throughout the LISP system and remain in
effect until a new value is specified.
• Global variables are generally declared using the defvar construct.
Example
(Defvar X 234)
(Write x)
output: (234)
• Since there is no type declaration for variables in LISP, you directly specify a value
for a symbol with the setq construct
• Example
(set q x 10 )
(format t "x = ~2d ~%" x )
• The above expression assigns the value 10 to the variable x
output: (x = 10)
LISP VARIABLE
LOCAL VARIABLE
• Local variables are defined within a given procedure. The parameters named as
arguments within a function definition are also local variables. Local variables are
accessible only within the respective function.
• Like the global variables, local variables can also be created using the setqconstruct.
• There are two other constructs - let and prog for creating local variables.
EXAMPLE:
 (let ( (x’ a) (y ’b) (z’ c)))
Output: x = A y = B z = C
 (prog ((x '(a b c))(y '(1 2 3))(z '(p q 10)))
Output : x = (A B C) y = (1 2 3) z = (P Q 10)
LISP CONSTANT
CONSTANT
In LISP, constants are variables that never change their values during program
execution.
Constants are declared using the defconstant construct.
EXAMPLE
PI value is 3.14
Value cannot be changed
LISP OPERATOR
OPERATOR
An operator is a symbol that tells the compiler to perform specific mathematical or logical
manipulations.
The operations allowed on data could be categorized as:
• Arithmetic Operations
• Comparison Operations
• Logical Operations
• Bitwise Operations
LISP OPERATOR
ARITHMETIC OPERATORS
IF VARIABLE A HOLDS 10 AND VARIABLE B HOLDS 20
DESCRIPTION EXAMPLE
+ Adds two operands (+AB) will give 30
- Subtracts second operand from the first (- A B) will give -10
* Multiplies both operands
(* A B) will give 200
LISP OPERATOR
OPERATOR DESCRIPTION EXAMPLE
/
Divides numerator by de-numerator
(/ B A) will give 2
Mod,rem Modulus Operator and remainder of after an
integer division
(mod B A )will give
0
incf Increments operator increases integer value
by the second argument specified
(incf A 3) will give
13
decf Decrements operator decreases integer
value by the second argument specified
(decf A 4) will give 9
COMPARISON OPERATOR
OPERATO
R
DESCRIPTION EXAMPLE
= Checks if the values of the operands are
all equal or not, if yes then condition
becomes true.
(= A B) is not true.
/= Checks if the values of the operands are
all different or not, if values are not equal
then condition becomes true.
(/= A B) is true.
Assume variable A holds 10 and variable B holds
20, then:
COMPARISON OPERATOR
> Checks if the values of the operands are monotonically decreasing. (> A B) is not true.
< Checks if the values of the operands are monotonically increasing. (< A B) is true.
>= Checks if the value of any left operand is greater than or equal to the
value of next right operand, if yes then condition becomes true.
(>= A B) is not true.
COMPARISON OPERATOR
<= Checks if the value of any left operand is less than
or equal to the value of its right operand, if yes then
condition becomes true.
(<= A B) is true.
max It compares two or more arguments and returns
the maximum value.
(max A B) returns 20
min It compares two or more arguments and returns
the minimum value.
(min A B) returns 20
LOGICAL OPERATION ON BOOLEAN
VALUES
Common LISP provides three logical operators: and, or, and not that operates on
Boolean values. Assume A has value nil and B has value 5, then:
OPETATOR DESCRIPTION
EXAMPLE
and It takes any number of arguments. The arguments are
evaluated left to right. If all arguments evaluate to non-nil, then
the value of the last argument is returned. Otherwise nil is
returned.
(and A B) will
return NIL.
or It takes any number of arguments. The arguments are
evaluated left to right until one evaluates to non-nil, in such
case the argument value is returned, otherwise it returns nil
(or A B) will
return 5
not It takes one argument and returns t if the
argument evaluates to nil.
(not A) will
return T.
BITWISE OPERATIONS ON NUMBERS
• Bitwise operators work on bits and perform bit-by-bit operation. The truth tables for
bitwise and, or, and xor operations are as follows
p q P and q P or q P xor q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
DECISION MAKING
• Decision making structures require that the programmer specify one or
more conditions to be evaluated or tested by the program, along with a
statement or statements to be executed if the condition is determined to be
true, and optionally, other statements to be executed if the condition is
determined to be false.
EXAMPLE
IF-ELSE STRUCTURE
DECISION MAKING
IF-ELSE STRUCTURE:
LISP LOOP
• There may be a situation, when you need to execute a block of code numbers of times.
A loop statement allows us to execute a statement or group of statements multiple
times and following is the general form of a loop statement in most of the programming
languages.
• LISP provides the following types of constructs to handle looping requirements.
LISP LOOP
LISP LOOP
CONSTRUC
T
DESCRIPTION
loop The loop construct is the simplest form of iteration provided by LISP. In its simplest form, it
allows you to execute some statement(s) repeatedly until it finds a return statement.
Loop for The loop for construct allows you to implement a for-loop like iteration as most common in
other languages.
do The do construct is also used for performing iteration using LISP. It provides a structured
form of iteration.
dotimes The dotimes construct allows looping for some fixed number of
iterations.
dolist The dolist construct allows iteration through each element of a list.
LISP ARRAY
• LISP allows you to define single or multiple-dimension arrays using the make-
array function. An array can store any LISP object as its elements.
• All arrays consist of contiguous memory locations. The lowest address corresponds to
the first element and the highest address to the last element.
• In LISP, an array element is specified by a sequence of non-negative integer
• indices. The length of the sequence must equal the rank of the array. Indexing starts
from zero.
• The number of dimensions of an array is called its rank.
LISP ARRAY
HOW TO DECLARE AN ARRAY
• For example, to create an array with 10- cells, named my-array, we can write:
• (setf my-array(make array(10)))
• The aref function allows accessing the contents of the cells. It takes two arguments, the
name of the array and the index value.
• For example, to access the content of the tenth cell, we write:
(aref my-array 9)

More Related Content

What's hot

Slides For Operating System Concepts By Silberschatz Galvin And Gagne
Slides For Operating System Concepts By Silberschatz Galvin And GagneSlides For Operating System Concepts By Silberschatz Galvin And Gagne
Slides For Operating System Concepts By Silberschatz Galvin And Gagne
sarankumar4445
 
CS5032 Case study Ariane 5 launcher failure
CS5032 Case study Ariane 5 launcher failureCS5032 Case study Ariane 5 launcher failure
CS5032 Case study Ariane 5 launcher failure
Ian Sommerville
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
 

What's hot (20)

02 Machine Learning - Introduction probability
02 Machine Learning - Introduction probability02 Machine Learning - Introduction probability
02 Machine Learning - Introduction probability
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
 
Hardware Acceleration for Machine Learning
Hardware Acceleration for Machine LearningHardware Acceleration for Machine Learning
Hardware Acceleration for Machine Learning
 
Slides For Operating System Concepts By Silberschatz Galvin And Gagne
Slides For Operating System Concepts By Silberschatz Galvin And GagneSlides For Operating System Concepts By Silberschatz Galvin And Gagne
Slides For Operating System Concepts By Silberschatz Galvin And Gagne
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
CS5032 Case study Ariane 5 launcher failure
CS5032 Case study Ariane 5 launcher failureCS5032 Case study Ariane 5 launcher failure
CS5032 Case study Ariane 5 launcher failure
 
Introduction to Neural Networks
Introduction to Neural NetworksIntroduction to Neural Networks
Introduction to Neural Networks
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Case study windows
Case study windowsCase study windows
Case study windows
 
Compiler question bank
Compiler question bankCompiler question bank
Compiler question bank
 
Lisp
LispLisp
Lisp
 
Chapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatzChapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatz
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marks
 
Theory of Computation Unit 5
Theory of Computation Unit 5Theory of Computation Unit 5
Theory of Computation Unit 5
 
Unit VI
Unit VI Unit VI
Unit VI
 
Bayesian networks
Bayesian networksBayesian networks
Bayesian networks
 
Machine learning Algorithm
Machine learning AlgorithmMachine learning Algorithm
Machine learning Algorithm
 
Ch1-Operating System Concepts
Ch1-Operating System ConceptsCh1-Operating System Concepts
Ch1-Operating System Concepts
 
Hill climbing algorithm
Hill climbing algorithmHill climbing algorithm
Hill climbing algorithm
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 

Similar to Lisp

Unit1 111206003944-phpapp02
Unit1 111206003944-phpapp02Unit1 111206003944-phpapp02
Unit1 111206003944-phpapp02
riddhi viradiya
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
nyomans1
 

Similar to Lisp (20)

Lecture 2 lisp-Overview
Lecture 2 lisp-OverviewLecture 2 lisp-Overview
Lecture 2 lisp-Overview
 
Lisp
LispLisp
Lisp
 
AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptx
 
Mbd dd
Mbd ddMbd dd
Mbd dd
 
Introduction to Programming in LISP
Introduction to Programming in LISPIntroduction to Programming in LISP
Introduction to Programming in LISP
 
intro.ppt
intro.pptintro.ppt
intro.ppt
 
Lisp, An Introduction.ppt
Lisp, An Introduction.pptLisp, An Introduction.ppt
Lisp, An Introduction.ppt
 
intro.ppt
intro.pptintro.ppt
intro.ppt
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptx
 
LISP.ppt
LISP.pptLISP.ppt
LISP.ppt
 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type script
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
Parquet - Data I/O - Philadelphia 2013
Parquet - Data I/O - Philadelphia 2013Parquet - Data I/O - Philadelphia 2013
Parquet - Data I/O - Philadelphia 2013
 
Advance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learningAdvance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learning
 
Unit1 111206003944-phpapp02
Unit1 111206003944-phpapp02Unit1 111206003944-phpapp02
Unit1 111206003944-phpapp02
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
 
Q-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxQ-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptx
 
Basics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest WayBasics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest Way
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Lisp

  • 2. TOPIC TO BE DISCUSSED An INTRODUCTION OF LISP ? FEATUERS OF LISP TEXT EDITOR LISP EXECUTOR LISP – BASIC SYNTAX LISP-DATA TYPES LISP CONSTANT LISP VARIABLES LISP OPERATOR DECISION MAKING LISP ARRAY LISP LOOP
  • 3. AN INTRODUCTION OF LISP ? •Lisp – List Processing language • John McCarthy invented LISP in 1958, shortly after the development of FORTRAN. It was first implement by Steve Russell on an IBM 704 computer • It is one of the most popular language for Artificial Intelligence programs • FEATURES OF LISP: • It is machine-independent • It allows updating the programs dynamically. • It provides high level debugging.
  • 4.
  • 5. FEATUERS OF LISP • It provides wide-ranging data types like, objects, structures, lists, vectors, adjustable arrays, hash-tables, and symbols. • It provides an object-oriented condition system. • It provides complete I/O library. • It provides extensive control structures. • Lisp was originally created as a practical mathematical notation for computer programs
  • 6. USES OF COMMON LISP USES OF CL • CL is a very successful language in that it is extremely powerful as an AI tool those that use it love it • And yet CL is a very uncommon language because it is very complicated most software development is in C++ (with some in Java, C#, C, Python, Ada, etc) such that few programmers would choose to use CL for development • The most important software developed from CL includes: – Emacs – G2 (a real-time expert system) – AutoCAD – Igor Engraver (musical notation editor and publisher) – Yahoo Store
  • 7. TEXT EDITOR • This will be used to type your program. Examples of few editors include Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi. • Name and version of text editor can vary on different operating systems. For example, Notepad will be used on Windows, and vim or vi can be used on windows as well as Linux or UNIX. • The files you create with your editor are called source files and contain program source code. The source files for Lisp programs are typically named with the extension ".lisp". • Before starting your programming, make sure you have one text editor in place and you have enough experience to write a computer program, save it in a file, finally execute it.
  • 8. TEXT EDITOR • The source code written in source file is the human readable source for your program. It needs to be "executed", to turn into machine language so that your CPU can actually execute the program as per instructions given. • This Lisp programming language will be used to execute your source code into final executable program. I assume you have basic knowledge about a programming language. • CLISP is the GNU Common LISP multi-architechtural compiler used for setting up LISP in Windows.
  • 10. LISP - BASIC SYNTAX LISP programs are made up of three basic building blocks: • atom • list • string ATOM: An atom is a number or string of contiguous characters. It includes numbers and special characters.
  • 12. DEFINE LIST LIST A list is a sequence of atoms and/or other lists enclosed in parentheses EXAMPLE (I AM A GENIOUS GIRL) (I AM A LIST) (A(A B C)D )
  • 13. DEFINE STRING STRING A string is a group of characters enclosed in double quotation marks EXAMPLE “I AM A STRING” “ HELLO WORLD” “PLEASE ENTER THE FOLLOWING DETAILS”
  • 14. ADDING COMMENTS COMMENTS The semicolon symbol (;) is used for indicating a comment line EXAMPLES “I AM A STRING” ; HELLO WORLD “PLEASE ENTER THE FOLLOWING DETAILS”
  • 15. CONCEPTS ABOUT LISP Following are some of the important points to note The basic numeric operations in LISP are +, -, *, and / LISP expressions are case-insensitive Naming Conventions in LISP • Name or symbols can consist of any number of alphanumeric characters other than whitespace, open and closing parentheses, double and single quotes, backslash, comma, colon, semicolon and vertical bar. To use these characters in a name, you need to use escape character (). • A name can have digits but not entirely made of digits, because then it would be read as a number. Similarly a name can have periods, but can't be made entirely of periods.
  • 16. LISP DATA TYPES LISP data types can be categorized as • Scalar types - for example, number types, characters, symbols etc. • Data structures - for example, lists, vectors, bit-vectors, and strings.
  • 17. LISP VARIABLES Global Variables • Global variables have permanent values throughout the LISP system and remain in effect until a new value is specified. • Global variables are generally declared using the defvar construct. Example (Defvar X 234) (Write x) output: (234) • Since there is no type declaration for variables in LISP, you directly specify a value for a symbol with the setq construct • Example (set q x 10 ) (format t "x = ~2d ~%" x ) • The above expression assigns the value 10 to the variable x output: (x = 10)
  • 18. LISP VARIABLE LOCAL VARIABLE • Local variables are defined within a given procedure. The parameters named as arguments within a function definition are also local variables. Local variables are accessible only within the respective function. • Like the global variables, local variables can also be created using the setqconstruct. • There are two other constructs - let and prog for creating local variables. EXAMPLE:  (let ( (x’ a) (y ’b) (z’ c))) Output: x = A y = B z = C  (prog ((x '(a b c))(y '(1 2 3))(z '(p q 10))) Output : x = (A B C) y = (1 2 3) z = (P Q 10)
  • 19. LISP CONSTANT CONSTANT In LISP, constants are variables that never change their values during program execution. Constants are declared using the defconstant construct. EXAMPLE PI value is 3.14 Value cannot be changed
  • 20. LISP OPERATOR OPERATOR An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. The operations allowed on data could be categorized as: • Arithmetic Operations • Comparison Operations • Logical Operations • Bitwise Operations
  • 21. LISP OPERATOR ARITHMETIC OPERATORS IF VARIABLE A HOLDS 10 AND VARIABLE B HOLDS 20 DESCRIPTION EXAMPLE + Adds two operands (+AB) will give 30 - Subtracts second operand from the first (- A B) will give -10 * Multiplies both operands (* A B) will give 200
  • 22. LISP OPERATOR OPERATOR DESCRIPTION EXAMPLE / Divides numerator by de-numerator (/ B A) will give 2 Mod,rem Modulus Operator and remainder of after an integer division (mod B A )will give 0 incf Increments operator increases integer value by the second argument specified (incf A 3) will give 13 decf Decrements operator decreases integer value by the second argument specified (decf A 4) will give 9
  • 23. COMPARISON OPERATOR OPERATO R DESCRIPTION EXAMPLE = Checks if the values of the operands are all equal or not, if yes then condition becomes true. (= A B) is not true. /= Checks if the values of the operands are all different or not, if values are not equal then condition becomes true. (/= A B) is true. Assume variable A holds 10 and variable B holds 20, then:
  • 24. COMPARISON OPERATOR > Checks if the values of the operands are monotonically decreasing. (> A B) is not true. < Checks if the values of the operands are monotonically increasing. (< A B) is true. >= Checks if the value of any left operand is greater than or equal to the value of next right operand, if yes then condition becomes true. (>= A B) is not true.
  • 25. COMPARISON OPERATOR <= Checks if the value of any left operand is less than or equal to the value of its right operand, if yes then condition becomes true. (<= A B) is true. max It compares two or more arguments and returns the maximum value. (max A B) returns 20 min It compares two or more arguments and returns the minimum value. (min A B) returns 20
  • 26. LOGICAL OPERATION ON BOOLEAN VALUES Common LISP provides three logical operators: and, or, and not that operates on Boolean values. Assume A has value nil and B has value 5, then: OPETATOR DESCRIPTION EXAMPLE and It takes any number of arguments. The arguments are evaluated left to right. If all arguments evaluate to non-nil, then the value of the last argument is returned. Otherwise nil is returned. (and A B) will return NIL. or It takes any number of arguments. The arguments are evaluated left to right until one evaluates to non-nil, in such case the argument value is returned, otherwise it returns nil (or A B) will return 5 not It takes one argument and returns t if the argument evaluates to nil. (not A) will return T.
  • 27. BITWISE OPERATIONS ON NUMBERS • Bitwise operators work on bits and perform bit-by-bit operation. The truth tables for bitwise and, or, and xor operations are as follows p q P and q P or q P xor q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1
  • 28. DECISION MAKING • Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false. EXAMPLE IF-ELSE STRUCTURE
  • 30. LISP LOOP • There may be a situation, when you need to execute a block of code numbers of times. A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages. • LISP provides the following types of constructs to handle looping requirements.
  • 32. LISP LOOP CONSTRUC T DESCRIPTION loop The loop construct is the simplest form of iteration provided by LISP. In its simplest form, it allows you to execute some statement(s) repeatedly until it finds a return statement. Loop for The loop for construct allows you to implement a for-loop like iteration as most common in other languages. do The do construct is also used for performing iteration using LISP. It provides a structured form of iteration. dotimes The dotimes construct allows looping for some fixed number of iterations. dolist The dolist construct allows iteration through each element of a list.
  • 33. LISP ARRAY • LISP allows you to define single or multiple-dimension arrays using the make- array function. An array can store any LISP object as its elements. • All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. • In LISP, an array element is specified by a sequence of non-negative integer • indices. The length of the sequence must equal the rank of the array. Indexing starts from zero. • The number of dimensions of an array is called its rank.
  • 35. HOW TO DECLARE AN ARRAY • For example, to create an array with 10- cells, named my-array, we can write: • (setf my-array(make array(10))) • The aref function allows accessing the contents of the cells. It takes two arguments, the name of the array and the index value. • For example, to access the content of the tenth cell, we write: (aref my-array 9)

Editor's Notes

  1. Refers to a software application that runs only on a particular type of computer. Programs that run on a variety of different types of computers are called machine independent.