SlideShare a Scribd company logo
AI
Programming
Language
(LISP)
BY:SURBHI SAROHA
SYLLABUS
– Introduction
– Manipulation of functions in LISP
– Definition of functions
– Predicates and conditionals
– The conditional COND
– Iteration and recursion
– Property lists and arrays
– Mapping functions
– Lambda functions and internal storage.
Introduction
– LISP became a common language for artificial intelligence (AI) programming, partly
owing to the confluence of LISP and AI work at MIT and partly because AI programs
capable of “learning” could be written in LISP as self-modifying programs.
– LISP has evolved through numerous dialects, such as Scheme and Common LISP.
– 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 particularly suitable for Artificial Intelligence programs, as it processes symbolic
information effectively.
– 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 of Lisp) etc.
Cont….
– 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 word length etc.
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 is expression-based.
Cont….
– It provides an object-oriented condition system.
– It provides a complete I/O library.
– It provides extensive control structures.
Manipulation of functions in LISP
– The following table provides some commonly used list manipulating functions.
– Sr.No.
– Function & Description
– 1.car
– It takes a list as argument, and returns its first element.
– 2.cdr
– It takes a list as argument, and returns a list without the first element
Cont….
– 3.cons
– It takes two arguments, an element and a list and returns a list with the element
inserted at the first place.
– 4.list
– It takes any number of arguments and returns a list with the arguments as member
elements of the list.
– 5.append
– It merges two or more list into one.
– 6.last
– It takes a list and returns a list containing the last element.
Cont…
– 7.member
– It takes two arguments of which the second must be a list, if the first argument
is a member of the second argument, and then it returns the remainder of the
list beginning with the first argument.
– 8.reverse
– It takes a list and returns a list with the top elements in reverse order.
Definition of functions
– The macro named defun is used for defining functions. The defun macro needs
three arguments −
– Name of the function
– Parameters of the function
– Body of the function
– Syntax for defun is −
– (defun name (parameter-list) "Optional documentation string." body)
Example 1
– Let's write a function named averagenum that will print the average of four
numbers. We will send these numbers as parameters.
– Create a new source code file named main.lisp and type the following code in it.
– (defun averagenum (n1 n2 n3 n4)
– (/ ( + n1 n2 n3 n4) 4)
– )
– (write(averagenum 10 20 30 40))
– When you execute the code, it returns the following result −
– 25
Predicates and conditionals
– Sr.No.Predicate & Description
– 1 atom
– It takes one argument and returns t if the argument is an atom or nil if otherwise.
– 2.equal
– It takes two arguments and returns t if they are structurally equal or nil otherwise.
– 3.eq
– It takes two arguments and returns t if they are same identical objects, sharing the
same memory location or nil otherwise.
Cont…..
– 4.eql
– It takes two arguments and returns t if the arguments are eq, or if they are numbers
of the same type with the same value, or if they are character objects that represent
the same character, or nil otherwise.
– 5.evenp
– It takes one numeric argument and returns t if the argument is even number or nil if
otherwise.
– 7.zerop
– It takes one numeric argument and returns t if the argument is zero or nil if
otherwise.
Cont…
– 8.null
– It takes one argument and returns t if the argument evaluates to nil, otherwise
it returns nil.
– 9.listp
– It takes one argument and returns t if the argument evaluates to a list otherwise
it returns nil.
– 10.greaterp
– It takes one or more argument and returns t if either there is a single argument
or the arguments are successively larger from left to right, or nil if otherwise.
Cont…
– 11.lessp
– It takes one or more argument and returns t if either there is a single argument or the
arguments are successively smaller from left to right, or nil if otherwise.
– 12.numberp
– It takes one argument and returns t if the argument is a number or nil if otherwise.
– 13.symbolp
– It takes one argument and returns t if the argument is a symbol otherwise it returns nil.
– 14.integerp
– It takes one argument and returns t if the argument is an integer otherwise it returns nil.
Cont…
– 15.rationalp
– It takes one argument and returns t if the argument is rational number, either a ratio or a
number, otherwise it returns nil.
– 16.floatp
– It takes one argument and returns t if the argument is a floating point number otherwise it
returns nil.
– 17.realp
– It takes one argument and returns t if the argument is a real number otherwise it returns nil.
– 18.complexp
– It takes one argument and returns t if the argument is a complex number otherwise it returns
nil.
Cont….
– 19..characterp
– It takes one argument and returns t if the argument is a character otherwise it returns nil.
– 20.stringp
– It takes one argument and returns t if the argument is a string object otherwise it returns nil.
– 21.arrayp
– It takes one argument and returns t if the argument is an array object otherwise it returns nil.
– 22.packagep
– It takes one argument and returns t if the argument is a package otherwise it returns nil.
The conditional COND
– The cond construct in LISP is most commonly used to permit branching.
– Syntax for cond is −
– (cond (test1 action1)
– (test2 action2)
– ...
– (testn actionn))
Cont….
– Each clause within the cond statement consists of a conditional test and an
action to be performed.
– If the first test following cond, test1, is evaluated to be true, then the related
action part, action1, is executed, its value is returned and the rest of the clauses
are skipped over.
– If test1 evaluates to be nil, then control moves to the second clause without
executing action1, and the same process is followed.
– If none of the test conditions are evaluated to be true, then the cond statement
returns nil.
Example
Create a new source code file named
main.lisp and type the following code in it −
– (setq a 10)
– (cond ((> a 20)
– (format t "~% a is greater than 20"))
– (t (format t "~% value of a is ~d " a)))
– When you click the Execute button, or type Ctrl+E, LISP executes it immediately
and the result returned is −
– value of a is 10
Iteration and recursion
– A program is called recursive when an entity calls itself. A program is call iterative
when there is a loop (or repetition).
– Example: Program to find the factorial of a number
– // C++ program to find factorial of given number
– #include<bits/stdc++.h>
– using namespace std;
–
– // ----- Recursion -----
– // method to find factorial of given number
– int factorialUsingRecursion(int n)
Cont….
– {
– if (n == 0)
– return 1;
– // recursion call
– return n * factorialUsingRecursion(n - 1);
– }
– // ----- Iteration -----
– // Method to find the factorial of a given number
– int factorialUsingIteration(int n)
Cont…
– {
– int res = 1, i;
– // using iteration
– for (i = 2; i <= n; i++)
– res *= i;
– return res;
– }
Cont…
– // Driver method
– int main()
– {
– int num = 5;
– cout << "Factorial of " << num <<
– " using Recursion is: " <<
– factorialUsingRecursion(5) << endl;
–
Cont…
– cout << "Factorial of " << num <<
– " using Iteration is: " <<
– factorialUsingIteration(5);
– return 0;
– }
Property lists and arrays
– 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.
– he number of dimensions of an array is called its rank.
– 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.
– For example, to create an array with 10- cells, named my-array, we can write −
– (setf my-array (make-array '(10)))
LISP - Arrays
Cont….
– 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)
The Property List
– Since its inception, Lisp has associated with each symbol a kind of tabular data
structure called a property list (plist for short). A property list contains zero or more
entries; each entry associates with a key (called the indicator), which is typically a
symbol, an arbitrary Lisp object (called the value or, sometimes, the property).
There are no duplications among the indicators; a property list may only have one
property at a time with a given name. In this way, given a symbol and an indicator
(another symbol), an associated value can be retrieved.
– A property list is very similar in purpose to an association list. The difference is that a
property list is an object with a unique identity; the operations for adding and
removing property-list entries are destructive operations that alter the property list
rather than making a new one. Association lists, on the other hand, are normally
augmented non-destructively (without side effects) by adding new entries to the
front (see acons and pairlis).
Cont….
– A property list is implemented as a memory cell containing a list with an even
number (possibly zero) of elements. (Usually this memory cell is the property-list
cell of a symbol, but any memory cell acceptable to setf can be used if getf and remf
are used.) Each pair of elements in the list constitutes an entry; the first item is the
indicator, and the second is the value. Because property-list functions are given the
symbol and not the list itself, modifications to the property list can be recorded by
storing back into the property-list cell of the symbol.
– When a symbol is created, its property list is initially empty. Properties are created
by using get within a setf form.
– Common Lisp does not use a symbol's property list as extensively as earlier Lisp
implementations did. Less-used data, such as compiler, debugging, and
documentation information, is kept on property lists in Common Lisp.
Mapping functions
– Mapping functions are a group of functions that could be applied successively to
one or more lists of elements. The results of applying these functions to a list are
placed in a new list and that new list is returned.
– For example, the mapcar function processes successive elements of one or more
lists.
– The first argument of the mapcar function should be a function and the remaining
arguments are the list(s) to which the function is applied.
– The argument function is applied to the successive elements that results into a
newly constructed list. If the argument lists are not equal in length, then the process
of mapping stops upon reaching the end of the shortest list. The resulting list will
have the same number of elements as the shortest input list.
Lambda functions and internal
storage
– At times you may need a function in only one place in your program and the
function is so trivial that you may not give it a name, or may not like to store it
in the symbol table, and would rather write an unnamed or anonymous
function.
– LISP allows you to write anonymous functions that are evaluated only when
they are encountered in the program. These functions are called Lambda
functions.
– You can create such functions using the lambda expression. The syntax for the
lambda expression is as follows −
Cont….
– (lambda (parameters) body)
– A lambda form cannot be evaluated and it must appear only where LISP expects to find a function.
– Example
– Create a new source code file named main.lisp and type the following code in it.
– (write ((lambda (a b c x)
– (+ (* a (* x x)) (* b x) c))
– 4 2 9 3)
– )
– When you execute the code, it returns the following result −
– 51
Internal storage
– "Lisp" is a family of languages, not a single language. Many languages in the family (e.g.,
Common Lisp) don't specify the internal representations, but rather the contract that the
structures and functions have to preserve. In the case of cons, it's roughly the equations:
– (car (cons x y)) == x
– (cdr (cons x y)) == y
– and the requirement that cons returns a new object each time it's called. In some Lisps, cons
cells are immutable, and so the requirement that a new object is returned isn't present.
– Of course, there are actually implementations, and they do actually have to store things, and
it's not unreasonable to ask how they do that. In general, it's probably best to think of a cons
cell as a structure big enough to hold two pointers, and probably some information holding its
type (so that it can be recognized as a cons cell). The pointers used by the implementaiton
might be tagged, though, so that if, e.g., the first three bits are some special values, the
"pointer" can be recognized as the encoding of some primitive value.
Thank you 

More Related Content

What's hot (20)

Reusibility vs Extensibility in OOAD
Reusibility vs Extensibility in OOADReusibility vs Extensibility in OOAD
Reusibility vs Extensibility in OOAD
Shivani Kapoor
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
Dr Sandeep Kumar Poonia
 
Logics for non monotonic reasoning-ai
Logics for non monotonic reasoning-aiLogics for non monotonic reasoning-ai
Logics for non monotonic reasoning-ai
ShaishavShah8
 
Deadlock
DeadlockDeadlock
Deadlock
Rajandeep Gill
 
object oriented methodologies
object oriented methodologiesobject oriented methodologies
object oriented methodologies
Amith Tiwari
 
Page Replacement
Page ReplacementPage Replacement
Page Replacement
chandinisanz
 
advanced computer architesture-conditions of parallelism
advanced computer architesture-conditions of parallelismadvanced computer architesture-conditions of parallelism
advanced computer architesture-conditions of parallelism
Pankaj Kumar Jain
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternatives
Pooja Dixit
 
First order predicate logic(fopl)
First order predicate logic(fopl)First order predicate logic(fopl)
First order predicate logic(fopl)
surbhi jha
 
OOAD
OOADOOAD
OOAD
yndaravind
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architectures
Pooja Dixit
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
Sara Ali
 
Distributed data processing
Distributed data processingDistributed data processing
Distributed data processing
Ayisha Kowsar
 
2.Problems Problem Spaces and Search.ppt
2.Problems Problem Spaces and Search.ppt2.Problems Problem Spaces and Search.ppt
2.Problems Problem Spaces and Search.ppt
Dr. Naushad Varish
 
Software design
Software designSoftware design
Software design
Syed Muhammad Hammad-ud-Din
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
Megha Sharma
 
File organization 1
File organization 1File organization 1
File organization 1
Rupali Rana
 
UML diagrams and symbols
UML diagrams and symbolsUML diagrams and symbols
UML diagrams and symbols
Kumar
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
SHIKHA GAUTAM
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
wahab khan
 
Reusibility vs Extensibility in OOAD
Reusibility vs Extensibility in OOADReusibility vs Extensibility in OOAD
Reusibility vs Extensibility in OOAD
Shivani Kapoor
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
Dr Sandeep Kumar Poonia
 
Logics for non monotonic reasoning-ai
Logics for non monotonic reasoning-aiLogics for non monotonic reasoning-ai
Logics for non monotonic reasoning-ai
ShaishavShah8
 
object oriented methodologies
object oriented methodologiesobject oriented methodologies
object oriented methodologies
Amith Tiwari
 
advanced computer architesture-conditions of parallelism
advanced computer architesture-conditions of parallelismadvanced computer architesture-conditions of parallelism
advanced computer architesture-conditions of parallelism
Pankaj Kumar Jain
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternatives
Pooja Dixit
 
First order predicate logic(fopl)
First order predicate logic(fopl)First order predicate logic(fopl)
First order predicate logic(fopl)
surbhi jha
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architectures
Pooja Dixit
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
Sara Ali
 
Distributed data processing
Distributed data processingDistributed data processing
Distributed data processing
Ayisha Kowsar
 
2.Problems Problem Spaces and Search.ppt
2.Problems Problem Spaces and Search.ppt2.Problems Problem Spaces and Search.ppt
2.Problems Problem Spaces and Search.ppt
Dr. Naushad Varish
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
Megha Sharma
 
File organization 1
File organization 1File organization 1
File organization 1
Rupali Rana
 
UML diagrams and symbols
UML diagrams and symbolsUML diagrams and symbols
UML diagrams and symbols
Kumar
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
SHIKHA GAUTAM
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
wahab khan
 

Similar to AI Programming language (LISP) (20)

AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptx
prakashvs7
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
Ravi Rao
 
Lisp
LispLisp
Lisp
huzaifa ramzan
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
wahab khan
 
INTRODUCTION TO LISP
INTRODUCTION TO LISPINTRODUCTION TO LISP
INTRODUCTION TO LISP
Nilt1234
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
DataminingTools Inc
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
 
Lisp
LispLisp
Lisp
sonukumar142
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
DataminingTools Inc
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
LISP Content
 
intro.ppt
intro.pptintro.ppt
intro.ppt
Luis Soza
 
Lisp, An Introduction.ppt
Lisp, An Introduction.pptLisp, An Introduction.ppt
Lisp, An Introduction.ppt
Luis Soza
 
intro.ppt
intro.pptintro.ppt
intro.ppt
AishwaryaKulal1
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Report about the LISP Programming Language
Report about the LISP Programming LanguageReport about the LISP Programming Language
Report about the LISP Programming Language
maldosmelandrew
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
Javier Gonzalez-Sanchez
 
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docxECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
SALU18
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
Yaser Jaradeh
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
Luis Goldster
 
Clqr a4-consec
Clqr a4-consecClqr a4-consec
Clqr a4-consec
Benjamin Brown
 
AI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptxAI UNIT-4 Final (2).pptx
AI UNIT-4 Final (2).pptx
prakashvs7
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
wahab khan
 
INTRODUCTION TO LISP
INTRODUCTION TO LISPINTRODUCTION TO LISP
INTRODUCTION TO LISP
Nilt1234
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
LISP Content
 
Lisp, An Introduction.ppt
Lisp, An Introduction.pptLisp, An Introduction.ppt
Lisp, An Introduction.ppt
Luis Soza
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Report about the LISP Programming Language
Report about the LISP Programming LanguageReport about the LISP Programming Language
Report about the LISP Programming Language
maldosmelandrew
 
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docxECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
SALU18
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
Yaser Jaradeh
 
Ad

More from Dr. SURBHI SAROHA (20)

Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHADeep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Dr. SURBHI SAROHA
 
MOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi sarohaMOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi saroha
Dr. SURBHI SAROHA
 
Mobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi sarohaMobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi saroha
Dr. SURBHI SAROHA
 
DEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi sarohaDEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi saroha
Dr. SURBHI SAROHA
 
Introduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptxIntroduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
Dr. SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
Dr. SURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
Dr. SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
Dr. SURBHI SAROHA
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
Dr. SURBHI SAROHA
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
Dr. SURBHI SAROHA
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
Dr. SURBHI SAROHA
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
Dr. SURBHI SAROHA
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
Dr. SURBHI SAROHA
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
Dr. SURBHI SAROHA
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
Dr. SURBHI SAROHA
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
Dr. SURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
Dr. SURBHI SAROHA
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
Dr. SURBHI SAROHA
 
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHADeep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Dr. SURBHI SAROHA
 
MOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi sarohaMOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi saroha
Dr. SURBHI SAROHA
 
Mobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi sarohaMobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi saroha
Dr. SURBHI SAROHA
 
DEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi sarohaDEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi saroha
Dr. SURBHI SAROHA
 
Introduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptxIntroduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
Dr. SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
Dr. SURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
Dr. SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Ad

Recently uploaded (20)

How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 

AI Programming language (LISP)

  • 2. SYLLABUS – Introduction – Manipulation of functions in LISP – Definition of functions – Predicates and conditionals – The conditional COND – Iteration and recursion – Property lists and arrays – Mapping functions – Lambda functions and internal storage.
  • 3. Introduction – LISP became a common language for artificial intelligence (AI) programming, partly owing to the confluence of LISP and AI work at MIT and partly because AI programs capable of “learning” could be written in LISP as self-modifying programs. – LISP has evolved through numerous dialects, such as Scheme and Common LISP. – 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 particularly suitable for Artificial Intelligence programs, as it processes symbolic information effectively. – 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 of Lisp) etc.
  • 4. Cont…. – 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 word length etc.
  • 5. 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 is expression-based.
  • 6. Cont…. – It provides an object-oriented condition system. – It provides a complete I/O library. – It provides extensive control structures.
  • 7. Manipulation of functions in LISP – The following table provides some commonly used list manipulating functions. – Sr.No. – Function & Description – 1.car – It takes a list as argument, and returns its first element. – 2.cdr – It takes a list as argument, and returns a list without the first element
  • 8. Cont…. – 3.cons – It takes two arguments, an element and a list and returns a list with the element inserted at the first place. – 4.list – It takes any number of arguments and returns a list with the arguments as member elements of the list. – 5.append – It merges two or more list into one. – 6.last – It takes a list and returns a list containing the last element.
  • 9. Cont… – 7.member – It takes two arguments of which the second must be a list, if the first argument is a member of the second argument, and then it returns the remainder of the list beginning with the first argument. – 8.reverse – It takes a list and returns a list with the top elements in reverse order.
  • 10. Definition of functions – The macro named defun is used for defining functions. The defun macro needs three arguments − – Name of the function – Parameters of the function – Body of the function – Syntax for defun is − – (defun name (parameter-list) "Optional documentation string." body)
  • 11. Example 1 – Let's write a function named averagenum that will print the average of four numbers. We will send these numbers as parameters. – Create a new source code file named main.lisp and type the following code in it. – (defun averagenum (n1 n2 n3 n4) – (/ ( + n1 n2 n3 n4) 4) – ) – (write(averagenum 10 20 30 40)) – When you execute the code, it returns the following result − – 25
  • 12. Predicates and conditionals – Sr.No.Predicate & Description – 1 atom – It takes one argument and returns t if the argument is an atom or nil if otherwise. – 2.equal – It takes two arguments and returns t if they are structurally equal or nil otherwise. – 3.eq – It takes two arguments and returns t if they are same identical objects, sharing the same memory location or nil otherwise.
  • 13. Cont….. – 4.eql – It takes two arguments and returns t if the arguments are eq, or if they are numbers of the same type with the same value, or if they are character objects that represent the same character, or nil otherwise. – 5.evenp – It takes one numeric argument and returns t if the argument is even number or nil if otherwise. – 7.zerop – It takes one numeric argument and returns t if the argument is zero or nil if otherwise.
  • 14. Cont… – 8.null – It takes one argument and returns t if the argument evaluates to nil, otherwise it returns nil. – 9.listp – It takes one argument and returns t if the argument evaluates to a list otherwise it returns nil. – 10.greaterp – It takes one or more argument and returns t if either there is a single argument or the arguments are successively larger from left to right, or nil if otherwise.
  • 15. Cont… – 11.lessp – It takes one or more argument and returns t if either there is a single argument or the arguments are successively smaller from left to right, or nil if otherwise. – 12.numberp – It takes one argument and returns t if the argument is a number or nil if otherwise. – 13.symbolp – It takes one argument and returns t if the argument is a symbol otherwise it returns nil. – 14.integerp – It takes one argument and returns t if the argument is an integer otherwise it returns nil.
  • 16. Cont… – 15.rationalp – It takes one argument and returns t if the argument is rational number, either a ratio or a number, otherwise it returns nil. – 16.floatp – It takes one argument and returns t if the argument is a floating point number otherwise it returns nil. – 17.realp – It takes one argument and returns t if the argument is a real number otherwise it returns nil. – 18.complexp – It takes one argument and returns t if the argument is a complex number otherwise it returns nil.
  • 17. Cont…. – 19..characterp – It takes one argument and returns t if the argument is a character otherwise it returns nil. – 20.stringp – It takes one argument and returns t if the argument is a string object otherwise it returns nil. – 21.arrayp – It takes one argument and returns t if the argument is an array object otherwise it returns nil. – 22.packagep – It takes one argument and returns t if the argument is a package otherwise it returns nil.
  • 18. The conditional COND – The cond construct in LISP is most commonly used to permit branching. – Syntax for cond is − – (cond (test1 action1) – (test2 action2) – ... – (testn actionn))
  • 19. Cont…. – Each clause within the cond statement consists of a conditional test and an action to be performed. – If the first test following cond, test1, is evaluated to be true, then the related action part, action1, is executed, its value is returned and the rest of the clauses are skipped over. – If test1 evaluates to be nil, then control moves to the second clause without executing action1, and the same process is followed. – If none of the test conditions are evaluated to be true, then the cond statement returns nil.
  • 20. Example Create a new source code file named main.lisp and type the following code in it − – (setq a 10) – (cond ((> a 20) – (format t "~% a is greater than 20")) – (t (format t "~% value of a is ~d " a))) – When you click the Execute button, or type Ctrl+E, LISP executes it immediately and the result returned is − – value of a is 10
  • 21. Iteration and recursion – A program is called recursive when an entity calls itself. A program is call iterative when there is a loop (or repetition). – Example: Program to find the factorial of a number – // C++ program to find factorial of given number – #include<bits/stdc++.h> – using namespace std; – – // ----- Recursion ----- – // method to find factorial of given number – int factorialUsingRecursion(int n)
  • 22. Cont…. – { – if (n == 0) – return 1; – // recursion call – return n * factorialUsingRecursion(n - 1); – } – // ----- Iteration ----- – // Method to find the factorial of a given number – int factorialUsingIteration(int n)
  • 23. Cont… – { – int res = 1, i; – // using iteration – for (i = 2; i <= n; i++) – res *= i; – return res; – }
  • 24. Cont… – // Driver method – int main() – { – int num = 5; – cout << "Factorial of " << num << – " using Recursion is: " << – factorialUsingRecursion(5) << endl; –
  • 25. Cont… – cout << "Factorial of " << num << – " using Iteration is: " << – factorialUsingIteration(5); – return 0; – }
  • 26. Property lists and arrays – 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. – he number of dimensions of an array is called its rank. – 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. – For example, to create an array with 10- cells, named my-array, we can write − – (setf my-array (make-array '(10)))
  • 28. Cont…. – 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)
  • 29. The Property List – Since its inception, Lisp has associated with each symbol a kind of tabular data structure called a property list (plist for short). A property list contains zero or more entries; each entry associates with a key (called the indicator), which is typically a symbol, an arbitrary Lisp object (called the value or, sometimes, the property). There are no duplications among the indicators; a property list may only have one property at a time with a given name. In this way, given a symbol and an indicator (another symbol), an associated value can be retrieved. – A property list is very similar in purpose to an association list. The difference is that a property list is an object with a unique identity; the operations for adding and removing property-list entries are destructive operations that alter the property list rather than making a new one. Association lists, on the other hand, are normally augmented non-destructively (without side effects) by adding new entries to the front (see acons and pairlis).
  • 30. Cont…. – A property list is implemented as a memory cell containing a list with an even number (possibly zero) of elements. (Usually this memory cell is the property-list cell of a symbol, but any memory cell acceptable to setf can be used if getf and remf are used.) Each pair of elements in the list constitutes an entry; the first item is the indicator, and the second is the value. Because property-list functions are given the symbol and not the list itself, modifications to the property list can be recorded by storing back into the property-list cell of the symbol. – When a symbol is created, its property list is initially empty. Properties are created by using get within a setf form. – Common Lisp does not use a symbol's property list as extensively as earlier Lisp implementations did. Less-used data, such as compiler, debugging, and documentation information, is kept on property lists in Common Lisp.
  • 31. Mapping functions – Mapping functions are a group of functions that could be applied successively to one or more lists of elements. The results of applying these functions to a list are placed in a new list and that new list is returned. – For example, the mapcar function processes successive elements of one or more lists. – The first argument of the mapcar function should be a function and the remaining arguments are the list(s) to which the function is applied. – The argument function is applied to the successive elements that results into a newly constructed list. If the argument lists are not equal in length, then the process of mapping stops upon reaching the end of the shortest list. The resulting list will have the same number of elements as the shortest input list.
  • 32. Lambda functions and internal storage – At times you may need a function in only one place in your program and the function is so trivial that you may not give it a name, or may not like to store it in the symbol table, and would rather write an unnamed or anonymous function. – LISP allows you to write anonymous functions that are evaluated only when they are encountered in the program. These functions are called Lambda functions. – You can create such functions using the lambda expression. The syntax for the lambda expression is as follows −
  • 33. Cont…. – (lambda (parameters) body) – A lambda form cannot be evaluated and it must appear only where LISP expects to find a function. – Example – Create a new source code file named main.lisp and type the following code in it. – (write ((lambda (a b c x) – (+ (* a (* x x)) (* b x) c)) – 4 2 9 3) – ) – When you execute the code, it returns the following result − – 51
  • 34. Internal storage – "Lisp" is a family of languages, not a single language. Many languages in the family (e.g., Common Lisp) don't specify the internal representations, but rather the contract that the structures and functions have to preserve. In the case of cons, it's roughly the equations: – (car (cons x y)) == x – (cdr (cons x y)) == y – and the requirement that cons returns a new object each time it's called. In some Lisps, cons cells are immutable, and so the requirement that a new object is returned isn't present. – Of course, there are actually implementations, and they do actually have to store things, and it's not unreasonable to ask how they do that. In general, it's probably best to think of a cons cell as a structure big enough to hold two pointers, and probably some information holding its type (so that it can be recognized as a cons cell). The pointers used by the implementaiton might be tagged, though, so that if, e.g., the first three bits are some special values, the "pointer" can be recognized as the encoding of some primitive value.