Overview AGENDA History Introduction Lisp Features Syntax Comparison structures Lambda expressions Conses and Lists List processing procedures Summary Lisp applications
Lisp was invented by John McCarthy in 1958 while he was at the MIT. McCarthy published its design in a paper in Communications of the ACM in 1960. Lisp was first implemented by Steve Russell on an IBM 704 computer. Connection to AI: Lisp was closely connected to AI research communities, especially on PDP-10 systems. Lisp was used as the implementation of the programming language Micro Planner which was used in the famous AI system SHRUDLU. Over its fifty-year history, lisp has spawned many variations on the core theme of an S-expression language. Lisp history
Introduction to Lisp(List processing) Lisp is second oldest high-level programming languages with a long history and a distinctive, fully parenthesized syntax. Lisp is a Tool to solve some of the most difficult problems in the world of computing. It is an example of elegant, minimalist language. Lisp is one of the most popular programming languages that is used for Artificial intelligence.
Lisp features Built in support for Lists. Atomic storage management. Dynamic Typing Uniform syntax. Interactive environment. Extensibility Standard macros. Special forms(loop, do, dotimes..)
Syntax (Data structures) Lists are surrounded by parenthesis. Ex: (),(()),((a,b,c)),((1,2),3,4) are all Lists. Atoms are string of characters beginning with letter, digit or special characters other than left “(“ and right “)” Ex: (a b c d) is a list of four elements(atoms) a,b,c,d Peace Of Mind 6678 Prefix notation is followed in Lisp. Operators first, followed by the arguments. Ex: (+ 4 5) adds 4 to 5 (/ 12 6)2
Function Definition List represents function calls as well as basic data structures. (factorial 4)12 (+4 2)6 Definition of a function (defun <f-name><parameter-list><body>) Ex: (defun square(X) (*XX)) SQUARE >(square2)4 >(square(square 2))16
Function inside function Ex: (+3(40)6)49 (+3(+3 3)4)13 Addition, subtraction and multiplication process 2*3 36 6
Comparing functions The comparison symbols are( => ,< ,> ,=<, >= ,<= ) These function return either True(T) or Nil. Ex: (= 4 4)T (< 4 4)NIL (> 5 1)T (>= 6 3)T (<= 4 3)NIL
Returns TRUE if values are not equal else NIL if values are equal.
Ex: (/4 2) 2
Max: It takes the maximum value of some numbers
Ex: (Max -3 3 40 150 -100)150
Min: It takes the minimum value of some numbers
Ex: (Min 3 4 10 -5)-5
Assigning functions: Syntax: setq( argument) Ex: (setq a 3)3 (* a 4)12 Explicit evaluation call; (eval a)3 Note: A quoted value is always kept untouched. (setq b ‘(+ a 4))(+ a 4)
4 equality predicates: (=, equal, eq, eql) for numerical values only. Ex: (= 2 4/2) T (setf a (1 2)) (1 2) (setf b (1 2)) (1 2) (equal a b)T (eql 3 9/3)T
Nil represents false and an empty list. Ex: (null nil)T (null())T (null ‘(a b))NIL (not ‘(a b))NIL
Lambda expressions Lambda operator is used to bind variables to values which are then evaluated within an expression. Arguments to lambda are list of arguments, and the expression or expressions to which the function evaluates. (lambda (arg) (arg+1)) evaluates to the function that, when applied takes one argument , binds it to arg and returns the number one greater then that argument. Ex: (lambda (arg) (arg+1) 4)5
Conses and lists A lisp list is a singly linked list, Each cell of this list is called a Cons, is composed of two pointers, called the car and cdr. If the given cons is taken to be the head of the linked list, then its car points to the first element of the list, and its cdr points to the rest of the List. A variable which refers to the list is simply a pointer to the first cons of the list. Parenthesized S-expressions represent Linked list structure.
List-processing procedures List can be directly created with the list procedure, which takes any number of arguments and returns the list of these arguments. Ex: (List 1 2 ‘ a 3) ( 1 2 a 3) (List 1 ‘ (2 3) 4)(1 (2 3) 4) For the linked lists cons procedure can be used to add an element to the front of the list. Ex: (cons 1 ‘ (2 3))(1 2 3) Append procedure append two or more lists to one another. Ex: (append ‘ (1 2) ‘ (3 4))(1 2 3 4)
Basic lisp examples Basic hello world program(print “Hello world”) To evaluate factorial on a number(n)
(defun factorial (n)
(if (<= n 1) 1 (* n (factorial(- n 1))))) //iterative version which uses common Lisp’s Loop Macro//
(defun factorial (n)
(loop for I from 1 to n for fac=1 then (* fac i) finally (return fac))) //using recursive function//
(defun –reverse (list)
(let ((return –value ‘())) (dolist (e list) (push e return-value)) return-value))
Lisp Summary Simple syntax. so, its very easy to parse. Programming in Lisp is distinguished from other programming languages due to its unique syntax and development mode. The interchangeability of code and data also gives Lisp instantly recognizable syntax. All lisp program code is written as S-expressions , or parenthesized lists.
Applications of Lisp programming Common Lisp is used to develop research applications(often in Artificial Intelligence) For rapid development of prototypes Lisp language is often used in interactive command line, which may be combined with an IDE. Common Lisp is used in many commercial applications, Including the Yahoo! Store Web-commerce site. Other visible applications people have developed using Lisp are:
Pick a tutorial of your choice and browse through it at your own pace. The tutorials section is free, self-guiding and will not involve any additional support. Visit us at www.dataminingtools.net Visit more self help tutorials