Beruflich Dokumente
Kultur Dokumente
MEERUT
Submitted to:
Submitted by:
INDEX
S.NO
TOPICS
DATE
REMARKS
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
LISP
LISP: List processing is an A.I. programming language developed by John M.C. Carthy
in the late of 1950s.LISP is a symbolic processing language that represents the
Information in list & manipulates these lists to derive the information. LISP language is
exclusively used for manipulating the list.The major characteristic is that the basic
elements are treated as symbols irrespective of whether they are numeric or
alphanumeric.
The basic data elements of LISP is an atom (a single word or number that
stands for some object or value)
LISP has two basic types of atoms1) Numbers 2) Symbols
1) Numbers: Represents a numeric value of any type of nos such as positive or
negative integers, floating or decimal are acceptable.
2) Symbols: Represents alphanumeric characteristics. It can be a combination of an
alphabets and numerals. A collection of nos or symbols constitute a list.
LISP Function:
A LISP program is a collection of small routines which define symbol function. In order
that complex function called primitives. These primitives serve commonly required
operation.
The basic primitives of LISP are:
1)Arithmetic primitives: The arithmetic primitive corresponds to the basic arithmetic
operation of addition, subtraction, multiplication & division. Since LISP used prefix
representation. All the arithmetic representation is carried out on data represented in the
prefix form.
Examples: To add two nos say 10 & 20.The prefix notation is +10 20
2) Boolean: The primitives provide a result which is Boolean in nature i.e. true or false
some such primitives are
(I) Atom: The purpose is to find out whether the element is atom or not.
Ex. (atom_xyz)
(II) Number: Determines atom is no. or not
Ex. (Number_20)
(III) List: Determines if i/p is list or not.
Ex. (List (5 10 15 20))
(IV) Odd: To find out whether the given i/p no. is odd.
Ex. (Odd_65)
(V) Even: Find out i/p is even or not.
Ex. (Even_20)
List Manipulation Primitive:
The purposes are
i)
Creating a new list.
ii)
Modifying the position of list.
iii)
Extracting the position of list.
In LISP the values are assigned to a variable by
SETQ primitive.
FUNCTION:
The function name DEFUN is used to define the function it requires the three argument.
1) The new function name.
2) The parameter for the function.
3) The function body or list code which performs the desired function operation.
The format is (DEFUN Name (parameter 1 Parameter 2Parameter n) Body)
Basic list manipulation function:
S.NO
1
Function Call
(CAR(A B C))
Value Return
A
(CDR(A B C))
BC
(CONSA(B C))
ABC
(LISTA(B C))
(A (B C))
Remarks
CAR takes one argument a list
and returns the first element.
CDR takes one argument list &
returns the first element
remove.
CONS take the two arguments
an element & a list and return a
list with the element inserted at
the beginning.
List takes any no. of arguments
& returns a list with the
argument as elements.
Function Call
Value Return
Remarks
(APPEND(A)(B C))
ABC
(LAST(A B C D))
(REVERSE(A(B C)D))
(D(B C )A)
Returns a list
containing the last
element.
Returns list with top
element in the
reverse order.
Programs:
10
11
5
15) Write a program to find the factorial of a number.
(DEFUN FACT(X)
(COND ((ZEROP X) 1)
(T (* X (FACT (- X 1))))))
FACT
(FACT 5)
OUTPUT:
120
16) Write a program to take temperature as a parameter and return HOT if the
temperature is greater than 100, COLD if it is less than 0 and OK otherwise.
(DEFUN TEMP (X)
(COND ((> X 100) HOT)
(T (COND ((< X 0) COLD)
(T OK)))))
TEMP
(TEMP 120)
OUTPUT:
HOT
12