C-LISP. LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute.

Slides:



Advertisements
Similar presentations
Introduction to LISP Programming of Pathway Tools Queries and Updates.
Advertisements

Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Lists in Lisp and Scheme a. Lists are Lisp’s fundamental data structures, but there are others – Arrays, characters, strings, etc. – Common Lisp has moved.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
1 Programming Languages and Paradigms Lisp Programming.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
Lisp Recitation (cse471/598 Fall 2007 ) Aravind Kalavagattu.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
First Lecture on Introductory Lisp Yun Peng. Why Lisp? Because it’s the most widely used AI programming language Because AI researchers and theoreticians.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
ISBN Chapter 15 Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages Introduction to.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
It is suggested that you use the Lisp interpreter available on the general machine (general.asu.edu). You are welcome to use other interpreters while developing,
LISP A brief overview. Lisp stands for “LISt Process” –Invented by John McCarthy (1958) –Simple data structure (atoms and lists) –Heavy use of recursion.
COMP 205 – Week 11 Dr. Chunbo Chu. Intro Lisp stands for “LISt Process” Invented by John McCarthy (1958) Simple data structure (atoms and lists) Heavy.
Lisp and Scheme I. Versions of LISP LISP is an acronym for LISt Processing language Lisp is an old language with many variants – Fortran is the only older.
(5.1) COEN Functional Languages  Functional programming basics  Atoms and lists; cons  Useful primitive functions  Predicates  Arithmetic functions.
Lisp: a history Developed by John McCarthy in the 1950’s. Developed by John McCarthy in the 1950’s. Only Fortran has higher “seniority” Only Fortran has.
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Lisp Laboratory gcLisp (Golden Common Lisp). Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon.
Functional Programming in Scheme
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
ISBN Chapter 15 Functional Programming Languages.
Common lisp A functional programming language. Useful URL:
CS 330 Programming Languages 11 / 21 / 2006 Instructor: Michael Eckmann.
CSE 341, S. Tanimoto Lisp Defining Functions with DEFUN Functions are the primary abstraction mechanism available in Lisp. (Others are structures.
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
Predicates, Functions and Files "I suppose I should learn Lisp, but it seems so foreign." - Paul Graham, Nov 1983.
ISBN Chapter 15 Functional Programming Languages.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Comparative Programming Languages Functional programming with Lisp/Scheme.
EZGİ GENÇ History Lisp is a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax. Originally.
LISP LISt Processing. History & Overview b b One of the oldest high level programming languages. b b First developed in 1958 by John McCarthy. b b Later.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (n-n-n-notes) Summer 2003 Dr. Carter Tiernan.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
Functional Programming
Functional Programming Languages
Functional Programming
History of Computing – Lisp
Section 15.4, 15.6 plus other materials
A I (Artificial Intelligence)
CS 326 Programming Languages, Concepts and Implementation
Getting Started with Lisp
LISP LISt Processing.
LISP A brief overview.
First Lecture on Introductory Lisp
Modern Programming Languages Lecture 21 Fakhar Lodhi
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
CS 36 – Chapter 11 Functional programming Features Practice
Modern Programming Languages Lecture 20 Fakhar Lodhi
Lisp and Scheme I.
LISP A brief overview.
Defining Functions with DEFUN
LISP LISt Processing.
Abstraction and Repetition
LISP LISt Processing.
Modern Programming Languages Lecture 18 Fakhar Lodhi
Lisp.
Presentation transcript:

C-LISP

LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute of Technology McCarthy published its design in a paper in Communications of the ACM in 1960, entitled "Recursive Functions of Symbolic Expressions and Their Computation by Machine, Communications of the ACM

Significant Language Features 3  The term “Lisp” itself originally stood for “LISt Processing.” Atoms & Lists - Lisp uses two different types of data structures, atoms and lists. Atoms are similar to identifiers, but can also be numeric constants Lists can be lists of atoms, lists, or any combination of the two Functional Programming Style - all computation is performed by applying functions to arguments. Variable declarations are rarely used. Uniform Representation of Data and Code - example: the list (A B C D) a list of four elements (interpreted as data) Reliance on Recursion - a strong reliance on recursion has allowed Lisp to be successful in many areas, including Artificial Intelligence. Garbage Collection - Lisp has built-in garbage collection, so programmers do not need to explicitly free dynamically allocated memory.

Advantages of LISP 4 Recursion: A program can call itself a sub routine Garbage Collector: Data storage is automatically recycled Uniform Representation: Program and data look the same Program can execution other program Interaction: User can combine program writing, compilation,testing,debugging,running in a single interacting session

Application of LISP 5 Artificial Intelligence Symbolical Algebraic Manipulation Natural Language Understanding Machine Translation Expert System Diagnosis System Automatic Programming (Robotics) Perception(Vision, Speech Understanding)

LISP Syntax 6 Syntax: Prefix notation – Operator first, arguments follow – E.g. (+ 3 2) adds 3 and 2 A lot of parentheses These define lists and also programs Examples: – (a b c d) is a list of 4 elements (atoms) a,b,c,d – (defun factorial (num) (cond ((<= num 0) 1) (t (* (factorial (- num 1)) num)) ))

LISP Data Types 7 There are two: atoms and lists. 1Atoms: Integer, Float,String, Character, symbol, Boolean etc a, 7, tom, my-age, nil, T – Evaluate an atom gives the value assigned that atom. Numbers are special--they always evaluate to themselves. (setq my-age 24) => 24 my-age => 24 – Reserved: nil and T nil => nil t => t – Case insensitive: aBc and ABC are the same atom

8 2 Data Types: Lists Lists: (a), (+ 6 7), (a (e f g) h), (), nil – Evaluating a list always invokes a function. (function-name arg1 … argn) (+ 6 7) => 13 (foo ) => Error (function not defined) (+ my-age 4) => 28 Lists are chains of pairs Can make other trees, etc as well

LISP Expressions 9 Numeric FunctionsMeaning (+ x 1 x 2... x n ) The sum of x 1, x 2,..., x n (* x 1 x 2... x n ) The product of x 1, x 2,..., x n (- x y) Subtract y from x (/ x y) Divide x by y (rem x y) The remainder of dividing x by y (abs x) The absolute value of x (max x 1 x 2... x n ) The maximum of x 1, x 2,..., x n (min x 1 x 2... x n ) The minimum of x 1, x 2,..., x n

function definition 10 Definition of a function (defun ( ) ) (defun square “computes square” (x) (* x x)) Lisp includes many built-in functions: +, *, -, /, max, min, sqrt Once a list is built, how do we access its members? – first and car give you the first element of a list. (first ‘(1 2 3)) => 1 (first ‘((a b) 2 3)) => (a b) (length ‘(a b c)) => 3

Relational Operators 11 Relational OperatorsMeaning (= x y) x is equal to y (/= x y) x is not equal to y (< x y) x is less than y (> x y) x is greater than y (<= x y) x is no greater than y (>= x y) x is no less than y

Logical Operators 12 Logical OperatorsMeaning (or x 1 x 2... x n ) Logical or (and x 1 x 2... x n ) Logical and (not x) Logical negation

13 Many ways to define iterations Commands: loop dolist dotimes do, do* Iterations: loop > (setq a 4) 4 > (loop (setq a (+ a 1)) (when (> a 7) (return a))) ;; return exists the loop 8 > (loop (setq a (- a 1)) (when (< a 3) (return))) NIL

14 Many ways to define iterations Commands: loop dolist dotimes do, do* Iterations: loop > (setq a 4) 4 > (loop (setq a (+ a 1)) (when (> a 7) (return a))) ;; return exists the loop 8 > (loop (setq a (- a 1)) (when (< a 3) (return))) NIL

15 Iterations: dolist > (dolist (x '( )) (print x)) NIL ;; NIL is returned by dolist Iterations: dotimes > (dotimes (i 4) (print i)) ;; starts from 0 and continues till limit NIL ;; returns NIL

16 Basic Functions CAR returns the head of a list CDR returns the tail of a list CONS inserts a new head into a list EQ compares two atoms for equality ATOM tests if its argument is an atom

17 Other useful Functions (NULL S) tests if S is the empty list (LISTP S) tests if S is a list LIST makes a list of its (evaluated) arguments  (LIST 'A '(B C) 'D) returns (A (B C) D)  (LIST (CDR '(A B)) 'C) returns ((B) C) APPEND concatenates two lists  (APPEND '(A B) '((X) Y) ) returns (A B (X) Y)

18 CAR The CAR of a list is the first thing in the list CAR is only defined for nonempty lists If L is Then (CAR L) is (A B C)A ( (X Y) Z)(X Y) ( ( ) ( ) )( ) ( ) undefined

19 CDR examples If L is Then (CDR L) is (A B C)(B C) ( (X Y) Z)(Z) ( ( ) ( ) )( ( ) ) ( ) undefined (X)( ) (defun hello () (write-string "Hello, World!")) First Program

Lab  Write Program to display following output 1 x 2 = 2 2 x 2 = 4 2 x 3 = 8  What is wrong with each of the following function definitions?  (defun speak (x y) (list ’all ’x ’is ’y))  (defun speak (x) (y) (list ’all x ’is y))  (defun speak ((x) (y)) (list all ’x is ’y))  Here is an example of the function MYFUN, a strange function of two inputs. (myfun ’alpha ’beta) => ((ALPHA) BETA) Write MYFUN. Test your function to make certain it works correctly. 20