PZ10CX - LISP Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 10.4.1 Appendix A.6.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 14 Functional Programming Languages - The design of the imperative languages is based directly.
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.
CSE 3341/655; Part 4 55 A functional program: Collection of functions A function just computes and returns a value No side-effects In fact: No program.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
1 Programming Languages and Paradigms Lisp Programming.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
LISP Programming. LISP – simple and powerful mid-1950’s by John McCarthy at M.I.T. “ LIS t P rocessing language” Artificial Intelligence programs LISP.
PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10CX - LISP Programming Language Design and Implementation.
PZ10A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10A - Heap storage Programming Language Design and.
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.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
Introductory Lisp Programming Lecture # 2 Main Topics –Basic Lisp data types –Lisp primitives –Details of list handling Cons cells (boxes) & their representation.
Common Lisp Derek Debruin Mark Larue Vinh Doan. Problem Domains There was a need in the early 1960s to define a programming language whose computational.
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester, 2010
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
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 by Namtap Tapchareon Lisp Background  Lisp was developed by John McCarthy in  Lisp is derives from List Processing Language. 
(5.1) COEN Functional Languages  Functional programming basics  Atoms and lists; cons  Useful primitive functions  Predicates  Arithmetic functions.
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
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.
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:
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
PZ03EX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03EX - ML Programming Language Design and Implementation.
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
ISBN Chapter 15 Functional Programming Languages.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Scheme Profs Tim Sheard and Andrew Black CS 311 Computational Structures.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
Comparative Programming Languages Functional programming with Lisp/Scheme.
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,
CS314 – Section 5 Recitation 9
Functional Programming
CS314 – Section 5 Recitation 10
Functional Programming Languages
Functional Programming
README FILE Programming Languages Design and Implementation
Modern Programming Languages Lecture 20 Fakhar Lodhi
Chapter 15 – Functional Programming Languages
(Functional Programming) Reference: R.Sebesta, Chapter 15
Lists in Lisp and Scheme
ML Programming Language Design and Implementation (4th Edition)
LISP LISt Processing.
LISP A brief overview.
First Lecture on Introductory Lisp
Lisp and Scheme I.
LISP A brief overview.
Announcements Quiz 5 HW6 due October 23
LISP LISt Processing.
Functional Programming: Lisp
LISP LISt Processing.
Modern Programming Languages Lecture 18 Fakhar Lodhi
15.2 Mathematical Functions
Programming Languages
Lisp.
More Scheme CS 331.
Presentation transcript:

PZ10CX - LISP Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 10.4.1 Appendix A.6 PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

LISP overview LISP was first designed and implemented by John McCarthy at MIT around 1960 LISP widely used for artificial intelligence research First language based on applicative execution LISP has equivalence of form between programs and data, which allows data structures to be executed as programs and programs to be modified as data In the late 1970s, Gerald Sussman and Guy Steele developed a variant named Scheme. This is the version that had the most impact on university use of LISP. In 1992 a standard for Common LISP was finally written PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

LISP features LISP functions are defined entirely as expressions. Data in LISP are rather restricted. Literal atoms and numeric atoms (numbers) are the basic elementary types. LISP provides a wide variety of primitives for the creation, destruction, and modification of lists (including property lists). Basic primitives for arithmetic are provided. LISP control structures are relatively simple. The expressions used to construct programs are written in strict Cambridge Polish form and may include conditional branching. Function parameters are transmitted either all by value or all by name depending on the classification of the function. Execution heavily dependent on heap storage PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

LISP (scheme) example Figure A.10 in text 1 %lisp [> are environment prompts.] 2 >; Store values as a list of characters 3 >(define (SumNext V) 4 (cond ((null V) (progn (print "Sum=") 0)) 5 (T (+ (SumNext (cdr V)) (car V)) ) )) 6 SUMNEXT 7 >; Create vector of input values 8 (defun GetInput(f c) 9 (cond ((eq c 0) nil) 10 (T (cons (read f) (GetInput f (- c 1)))))) 11 GETINPUT 12 >(defun DoIt() 13 (progn 14 (setq infile (open '"lisp.data")) 15 (setq array (GetInput infile (read infile))) 16 (print array) 17 (print (SumNext array)))) Figure A.10 in text PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

LISP data structures Developed in 1960 by McCarthy at MIT PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Basic LISP operations Operators: (car ( 1 2 3 )) = 1  head of list (cdr ( 1 2 3 ) ) = ( 2 3 )  tail of list (cons a ( b c d ) ) = ( a b c d )  join operation (cons ( car ( cdr (a b c))) ( c d)) = (b c d) But: (cons (a b ) ( c d ) ) = ( ( a b ) c d ) (+ 1 2) = 3  [also - * /] Conditional: (cond (predicate1) (predicate2) … (T expression))  Evaluate each predicate and and stop when first predicate becomes true (T) Example if-then-else: (cond ((eq A 2)(print “true”)) (T (print “false”)) Define functions: applicative like in ML: (defun x) (expression) PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Some simple functions atom - true if argument is an atom (not a list) null - true if list is empty numberp - true if argument is a number append - appends two lists eq - true if both arguments point to the same object equal - true if both arguments have the same list members quote - (quote X) = X [Also written as (‘X)] [See next slide] and, or, not - Logical operations read - read from keyboard print - write to keyboard bye - exit LISP environment PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

LISP storage LISP is first language that makes heavy use of heap storage. Storage reclaimed automatically by LISP environment when out of space. Uses space efficiently. Each LISP item is a fixed size object allocated in the heap. As example shows, although based on a heap, LLISP still needs a stack for execution. Example: Trace execution of: (defun f1(x y z) (cons x (f2 y z ) ) ) (defun f2(v w) (cons v w) ) PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000