Lisp Laboratory gcLisp (Golden Common Lisp). Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon.

Slides:



Advertisements
Similar presentations
CS 63 LISP Philip Greenspun's Tenth* Rule of Programming:
Advertisements

ANSI Common Lisp 3. Lists 20 June Lists Conses List Functions Trees Sets Stacks Dotted Lists Assoc-lists.
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.
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.
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.
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)
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.
Lisp Recitation (cse471/598 Fall 2007 ) Aravind Kalavagattu.
PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10CX - LISP Programming Language Design and Implementation.
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).
CMSC 471 LISP. Why Lisp? Because it’s the most widely used AI programming language Because it’s good for writing production software (Graham article)
TES3111 Oct 2001 Data Structures S-Expression - Symbolic expression. It can be an Atom, a List or a collection of S- Expression enclosed by (…) Atom -
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.
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 by Namtap Tapchareon Lisp Background  Lisp was developed by John McCarthy in  Lisp is derives from List Processing Language. 
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.
Using Harlequin LispWorks. Using LispWorks On BURKS 5, the file is lwper410.exe Start up LispWorks; you get two windows –Listener 1 –LispWorks Personal.
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
For Monday Read Chapter 3 Homework: –Lisp handout 2.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Functional Programming in Scheme
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
KU NLP Artificial Intelligence1 Ch 15. An Introduction to LISP q 15.0 Introduction q 15.1 LISP: A Brief Overview  Symbolic Expressions, the Syntactic.
Common lisp A functional programming language. Useful URL:
CS 330 Programming Languages 11 / 21 / 2006 Instructor: Michael Eckmann.
LISP John McCarthy and Marvin Minsky formed MIT’s AI Project in Suggested reading: John McCarthy’s home page
CS 330 Programming Languages 11 / 13 / 2008 Instructor: Michael Eckmann.
Predicates, Functions and Files "I suppose I should learn Lisp, but it seems so foreign." - Paul Graham, Nov 1983.
Functional Programming CS331 Chapter 14. Functional Programming Original functional language is LISP –LISt Processing –The list is the fundamental data.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
Building user-defined functions: the progressive envelopment technique The idea: define combinations of LISP primitives through a sequence of experiments.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Control in LISP More on Predicates & Conditionals.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Functional Programming: Lisp MacLennan Chapter 10.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
Comparative Programming Languages Functional programming with Lisp/Scheme.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
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.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Section 15.4, 15.6 plus other materials
Modern Programming Languages Lecture 20 Fakhar Lodhi
CS 326 Programming Languages, Concepts and Implementation
Lists in Lisp and Scheme
LISP LISt Processing.
LISP A brief overview.
PZ10CX - LISP Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section Appendix A.6.
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
Lisp and Scheme I.
LISP A brief overview.
Defining Functions with DEFUN
LISP LISt Processing.
Abstraction and Repetition
Functional Programming: Lisp
LISP LISt Processing.
Programming Languages
Lisp.
Presentation transcript:

Lisp Laboratory gcLisp (Golden Common Lisp)

Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon had developed “list processing” and created IPL (Information Processing Language), abstract for manipulated symbols and list. When FORTRAN had build, McCarthy designed a new languae, LISP ( List Processor), drew on idea from IPL, FORTRAN and FLPL, run on IBM704 In the 1970s Guy Steele and Gerald Sussman defined Scheme, combined Algol and Lisp.

Lect. ratchadaporn kanawong3 The history of Lisp By the early 1980s, there were dozens of incompatible Lisp. A project to define a Common Lisp that would merge the best feature of existing dialects into a coherent whole. The first edition of the Common Lisp standard appeared in Many idea in programming systems such as interpreted and compiled function, garbage collection, recursive function calls, source-level tracing and debugging, and syntax-directed editors.

Lect. ratchadaporn kanawong4 Installation Download GC-Lisp from web of course Double click for unzip file Extract at “C:\” Appear dialog, creating folder “C:\GCLisp” Answer OK

Lect. ratchadaporn kanawong5 Startup gclisp Click start bottom and click run and type, or Double Click Gclisp.exe for loading in “C:\gclisp” directory

Lect. ratchadaporn kanawong6 GC-LISP Environment You will see window of GCLISP as

Lect. ratchadaporn kanawong7 Some Command:Hot Key -H to get help -E to enter the LISP Explorer -E to enter the editor to exit editor into Lisp Environment to load a file into the editor to save a file to save a file as another name

Lect. ratchadaporn kanawong8 Command line Type these command follow symbol “*”

Lect. ratchadaporn kanawong9 Prefix command All command is in parentheses ( ) It will evaluate when we type “)” Command form in term prefix (function )

Lect. ratchadaporn kanawong10 GMAC editor window Press -E for getting GMAC editor to save file and back gcLisp

Lect. ratchadaporn kanawong11 Load file into gclisp environment Load first.lsp * (load ‘first)

Lect. ratchadaporn kanawong12 Functions and data The term data means information such as Numbers Words Lists of things The function operates on the data in some way and the result is output

Lect. ratchadaporn kanawong13 Functions Box Function on Data Function data result

Lect. ratchadaporn kanawong14 A table function in lisp +Adds two numbers -Subtracts the second from the first *Multiplies two nubmers /Divides the first by the second ABSAbsolute value of a number

Lect. ratchadaporn kanawong15 SYMBOLs Symbols are another type of data in Lisp It is more interesting than numbers Symbols are named English words Phrases Common abbreviations Symbol may be letters, number, and special characters such as hyphen(-)

Lect. ratchadaporn kanawong16 EXERCISE Following : symbol or number AARDVARD GO /7 -12

Lect. ratchadaporn kanawong17 THE SPECIAL SYMBOLs Two Lisp symbols have special meaning attached to them. TTruth, “yes” NILFalsity, emptiness, “no” ***NIL can express by ( )

Lect. ratchadaporn kanawong18 Some Predicate A predicate is a question-answering function (likely yes-or-no question) Two predicate : NUMBERP (number predicate) to check whether expression is number SYMBOLP (symbol predicate) to check whether expression is symbol

Lect. ratchadaporn kanawong19 Test Predicates Type following this screen

Lect. ratchadaporn kanawong20 More Predicates ZEROPto check zero ODDPto check odd number EVENPto check even number <to compare first < second >to compare first > second EQUALto compare first = second NOTto opposite

Lect. ratchadaporn kanawong21 Test Predicate * (ZEROP 0) * (ZEROP 5) * (ODDP 1) * (ODDP 2) * (EVENP 1) * (EVENP 2) * (< 2 1) * (> 2 1) * (EQUAL 1 (- 3 2)) * (NOT NIL)

Lect. ratchadaporn kanawong22 Set variable Binding free variables Sets variable to the value or the expression by (setq variable ) * (setq x 5) * (setq a ‘(1 2 3 x y z)) * (setq b ‘(red green blue))

Lect. ratchadaporn kanawong23 Lists LISP is named from LISt Processor Lists are central data type, the most versatile data type Lists are important because they can be made to represent practically anything: sets, tables, and graphs and even English sentences.

Lect. ratchadaporn kanawong24 Example of Lists (RED GREEN BLUE) ( ) (Lisp is powerful) RED GREENBLUE NIL

Lect. ratchadaporn kanawong25 NESTED LISTs A list may contain other lists as elements Given the three lists (BLUE SKY) (GREEN GRASS) (BROWN EARTH) Make list that consists of the above lists ((BLUE SKY) (GREEN GRASS) (BROWN EARTH))

Lect. ratchadaporn kanawong26 LENGTH OF LISTs The length of a list is the number of elements it has (LENGTH ) * (setq x ‘(HI MOM)) * (LENGTH x) * (setq a ‘((blue sky) (green grass) (brown earth))) * (LENGTH a)

Lect. ratchadaporn kanawong27 Exercise How many elements of following lists have? (OPEN DOOR PLEASE) (OPEN (THE DOOR) PLEASE) ((1 2) (2 3) (3 4) (4 5) (5 6)) ((ONE) FOR ALL (AND (TWO (FOR ME)))) (A (B C) D ()) (A B (C D) ())

Lect. ratchadaporn kanawong28 Construct of List We have three function to make list (cons ) (list ) (append )

Lect. ratchadaporn kanawong29 Constructing Lists Using ‘cons’  (cons ‘(a b) ‘(c d))((A B) C D) Using ‘append’  (append ‘(a b) ‘(c d))(A B C D) Using ‘list’  (list ‘(a b) ‘(c d))((A B) (C D))

Lect. ratchadaporn kanawong30 Make List Example Type and look the result

Lect. ratchadaporn kanawong31 Element order in list In list are considered into two part : head and tail (a b c d) (b c d) a head tail CAR is function to get head part of list CDR is function to get tail part of list

Lect. ratchadaporn kanawong32 Result of car & cdr * (setq a ‘(x y z)) * (car a) * (cdr a) * (setq b ‘((blue sky) (green grass) (brown earth))) * (car b) * (cdr b) * (caar b) * (cadr b) * (cdar b) * (cddr b)

Lect. ratchadaporn kanawong33 Meaning function c?r (caar x)-(car (car x)) (cadr x)-(car (cdr x)) (cdar x)- (cdr (car x)) (cddr x)-(cdr (cdr x)) (caadr x)- (car (car (cdr x))) (caddr x)-(car (cdr (cdr x))) (cdddr x)- (cdr (cdr (cdr x)))

Lect. ratchadaporn kanawong34 Creating Function The syntax for creating function as: (defun (parameter-list) )

Lect. ratchadaporn kanawong35 Example Function Look this example (defun call-up (caller callee) (list ‘hello callee ‘this ‘is caller ‘calling)) * (call-up ‘FRED ‘WANDA)

Lect. ratchadaporn kanawong36 Example Function Look this example (defun double (n) (* n 2)) * (double 2)

Lect. ratchadaporn kanawong37 Example Function (defun absolute-value(x) (cond ((< x 0) (- x)) ((>= x 0) x))) * (absolute-value 2) (defun absolute-value(x) (cond ((< x 0) (- x)) (t x))) (defun absolute-value(x) (if (< x 0) (- x) x))

Lect. ratchadaporn kanawong38 Conditionals(1) Its form as: (cond ( ) …….. ( ))

Lect. ratchadaporn kanawong39 Conditionals Its form as: Some predicates for condition test: (if [ ]) = > = <= oddp evenp numberp minusp zerop plusp member atom listp null equal and or not

Lect. ratchadaporn kanawong40 Recursive Functions (defun my-member(element list) (cond ((null list) nil) ((equal element (car list)) list) (t (my-member element (cdr list))))) (defun my-length(list) (cond ((null list) 0) (t (+ (my-length(cdr list)) 1))))

Lect. ratchadaporn kanawong41 Recursive Functions (defun count-atoms(list) (cond ((null list) 0) ((atom list) 1) (t (+ (count-atoms (car list)) (count-atoms (cdr list))))))

Lect. ratchadaporn kanawong42 Linear or cdr recursion (length ((1 2) 3 (1 (4 (5))))) (length (3 (1 (4 (5))))) (length ((1 (4 (5))))) (length ())

Lect. ratchadaporn kanawong43 Tree of recursion

Lect. ratchadaporn kanawong44 Side Effects *(defun f(x) (setq inc (+ inc 1)) (+ x inc)) *(setq inc 0) *(f 4) *inc *x *(defun foo(x) (setq x (+ x 1)) x) *(setq y 1) *(foo y) *y *x