1. CS552
Artificial Intelligence-
LISP (Programming Language)
BSCS-5th Semester-2020
Prepared By:
Mr. Rahat Ullah
r2mpak@gmail.com
Department Of
Computer Science
Government Degree
College Gulabad Dir (L)
KPK Pakistan
2. What is LISP?
Lisp (historically LISP) is a family of programming languages.
Lisp is an acronym for List Processing
John McCarthy invented LISP in 1958, shortly after the development of
FORTRAN.
It was first implemented by Steve Russell on an IBM 704 Computer.
It is a language which is fully parenthesized, prefix notation
Lisp is the second-oldest high-level programming language in widespread use
today.
Today, the best-known general-purpose Lisp dialects are Racket, Common
Lisp, Scheme and Clojure
As one of the earliest programming languages, Lisp pioneered many ideas
in computer science, including tree data structures, automatic storage
management, dynamic typing, conditionals, higher-order
functions, recursion, the self-hosting compiler, and the read–eval–print loop
A function call or syntactic form is written as a list with the function or operator's
name first, and the arguments following; for instance, a function f that takes three
arguments would be called as (f arg1 arg2 arg3).
3. What is Common LISP?
Common Lisp originated, during the 1980s and 1990s, in an attempt to unify the
work of several implementation groups that were successors to Maclisp, like
ZetaLisp and NIL (New implementation Implementation of Lisp) etc.
It serves as a common language, which can be easily extended for specific
implementation.
Programs written in Common LISP do not depend on machine-specific
characteristics, such as Programs written in Common LISP do not depend on
machine-specific characteristics, such as word length etc.
4. Features of Common LISP?
It is machine-independent
It uses iterative design methodology, and easy extensibility.
It allows updating the programs dynamically.
It provides high level debugging.
It provides advanced object-oriented programming.
It provides a convenient macro system.
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 a complete I/O library.
It provides extensive control structures
5. Applications built in LISP?
Large successful applications built in LISP.
1. Emacs
2. G2
3. AutoCad
4. Igor Engraver
5. Yahoo Store
6. LISP environment Setup?
If you are still willing to set up your environment for Lisp programming language,
you need the following two softwares available on your computer
1. 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.
• 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"
7. LISP environment Setup…
2. The Lisp Executer
• 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.
• CLISP is the GNU Common LISP multi-architechtural compiler used for
setting up LISP in Windows. The windows version emulates a unix
environment using MingW under windows.
• Installer takes care of this and automatically adds clisp to the windows
PATH variable.
• You can get the latest CLISP for Windows from here
https://sourceforge.net/projects/clisp/files/latest/download
9. LISP-Program Structure
LISP expressions are called symbolic expressions or s-expressions.
The s-expressions are composed of three valid objects, atoms, lists and
strings.
Any s-expression is a valid program.
LISP programs run either on an interpreter or as compiled code.
The interpreter checks the source code in a repeated loop, which is also
called the read-evaluate-print loop (REPL).
It reads the program code, evaluates it, and prints the values returned by the
program
10. LISP-Program Structure
LISP expressions are called symbolic expressions or s-expressions.
The s-expressions are composed of three valid objects, atoms, lists and
strings.
Any s-expression is a valid program.
LISP programs run either on an interpreter or as compiled code.
The interpreter checks the source code in a repeated loop, which is also
called the read-evaluate-print loop (REPL).
It reads the program code, evaluates it, and prints the values returned by the
program
11. LISP-Basic Building Blocks
LISP programs are made up of three basic building blocks −
1. Atom
An atom is a number or string of contiguous characters. It includes
numbers and special characters. Following are examples of some valid
atoms: name, 12300888, *hello*, ABC#123, hello-rahat123
2. List
A list is a sequence of atoms and/or other lists enclosed in parentheses.
Following are examples of some valid lists −
( i am a list i am a list) , (a a ( a b c a b c) d e fgh d e fgh) ,
(father tom father tom ( susan bill joe susan bill joe)) ))
( )
12. LISP-Basic Building Blocks
3. String
A string is a group of characters enclosed in double quotation marks.
Following are examples of some valid strings
" I am a string" , "a ba c d efg #$%^&!“ , "Please enter your text here:"
"Hello from RK'! “
Adding Comments:
The semicolon symbol (;) is used for indicating a comment line. For
Example,
(write-line "Hello World" "Hello World") ; greet the world
; tell them your whereabouts
(write-line "I am at ‘CS-5th semester'! Learning LISP")
13. LISP-The “Hello World” Program
Create new source code file named Exaple.lisp and type the following code in it.
(write-line "Hello World")
(write-line "I am at ‘CS-5th Semester'! Learning LISP")
When you click the Execute button, or type Ctrl+E, LISP executes it immediately
and the result returned is
Hello World
I am at ‘CS-5th Semester'! Learning LISP
14. LISP-Some Notable Points
Following are some of the important points to note
The basic numeric operations in LISP are +, -, *, and /
LISP represents a function call f(x) as (f x), for example cos(45) is written as
cos 45
LISP expressions are case-insensitive, cos 45 or COS 45 are same.
LISP tries to evaluate everything, including the arguments of a function. Only
three types of elements are constants and always return their own value
a) Numbers
b) The letter t, that stands for logical true.
c) The value nil, that stands for logical false, as well as an empty list.
15. LISP-A Simple Program
Let us write an s-expression to find the sum of three numbers 7, 9 and 11. To do
this, we can type at the interpreter prompt
(+ 7 9 11 11)
LISP returns the resul
27
If you would like to run the same program as a compiled code, then create a LISP
source code file named myprog.lisp and type the following code in it.
(write write (+ (+ 7 9 11 11))
When you click the Execute button, or type Ctrl+E, LISP executes it immediately
and the result When returned is
27
16. LISP-Prefix Notation
You might have noted that LISP uses prefix notation.
In the above program the + symbol works as the function name for the process of
summation of the numbers.
In prefix notation, operators are written before their operands. For example, the
expression,
a * ( b + c ) / d will be written as (/ (* a (+ b c)) d)
Let us take another example, let us write code for converting Fahrenheit temp of
60F to the centigrade scale
The mathematical expression for this conversion will be (60 * 9 / 5) + 32
Create a source code file named temp.lisp and type the following code in it.
(write(+ (* (/ 9 5)60) 32)) by executing the file you will get the result as 140
17. Department Of Computer Science
Government Degree College Gulabad Dir (L)
KPK Pakistan | r2mpak@gmail.com
Thanks for the
Attention!