Lisp Tutorial Click on Xlisp icon – you enter the interpreter

Slides:



Advertisements
Similar presentations
Lisp Control and Data Structures CIS 479/579 Bruce R. Maxim UM-Dearborn.
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.
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.
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is a good way to learn more about programming languages  Interpreters are.
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.
Defining functions in lisp In lisp, all programming is in terms of functions A function is something which –takes some arguments as input –does some computing.
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.
Scheme examples. Recursion Iteration is achieved via recursion Selection is achieved via COND Review the following examples to learn to think recursively.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
General pattern for selecting some elements of a list This negatives example illustrates a general pattern: If you want a function which selects some elements.
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.
CSE S. Tanimoto Lisp Lisp S-Expressions: ATOMs Every Lisp object is either an ATOM or a CONS Symbols and numbers are kinds of atoms: X, APPLE,
1 Lists in Lisp and Scheme. 2 Lists are Lisp’s fundamental data structures. Lists are Lisp’s fundamental data structures. However, it is not the only.
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
Common Lisp Macros Read for Input Macros Macro lifetime Macro syntax
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.
CSE 341, S. Tanimoto Lisp Defining Functions with DEFUN Functions are the primary abstraction mechanism available in Lisp. (Others are structures.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
CS220 Programming Principles 프로그래밍의 이해 2002 가을학기 Class 6 한 태숙.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Functional Programming: Lisp MacLennan Chapter 10.
CSE S. Tanimoto Lisps's Basic Functionality 1 LISP: Basic Functionality S-expressions Conses Lists Predicates Evaluation and quoting Conditional.
Comparative Programming Languages Functional programming with Lisp/Scheme.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Section 15.4, 15.6 plus other materials
Lisp S-Expressions: ATOMs
CS 550 Programming Languages Jeremy Johnson
Modern Programming Languages Lecture 20 Fakhar Lodhi
Getting Started with Lisp
Lists in Lisp and Scheme
LISP LISt Processing.
CS 270 Math Foundations of CS Jeremy Johnson
LISP A brief overview.
Using Lisp Lisp is a interactive system
First Lecture on Introductory Lisp
Writing LISP functions
Modern Programming Languages Lecture 20 Fakhar Lodhi
Lisp: Using Functions as Data
LISP A brief overview.
Lisp: Representation of Data
Defining Functions with DEFUN
LISP LISt Processing.
Abstraction and Repetition
Functional Programming: Lisp
Lisp: Using Functions as Data
LISP: Basic Functionality
LISP LISt Processing.
Modern Programming Languages Lecture 18 Fakhar Lodhi
LISP: Basic Functionality
LISP: Basic Functionality
Programming Languages
Lisp.
Lisp: Representation of Data
LISP primitives on sequences
Lists in Lisp and Scheme
Presentation transcript:

Lisp Tutorial Click on Xlisp icon – you enter the interpreter You can now Define functions Load program files – with .lsp extension Execute Lisp functions

> is the lisp prompt > mylist > (mylist) Error: unbound variable mylist > (mylist) Error: unbound function mylist (setq mylist ‘(a b c d)) (A B C D)

(cdr (car mylist)) ? What will happen (cdr mylist) (B C D) (car (cdr mylist) …waiting ) .. Need to complete the balanced parenthesis B (cdr (car mylist)) ? What will happen Error: bad argument type - A

> (equal nil mylist) > (atom mylist) > (listp mylist) > (equal nil mylist)

> (null (cdr mylist) ) > (cdddr mylist) > (list (car mylist)) Error: unbound variable cdr > (null (cdr mylist) ) nil > (cdddr mylist) (D) > (list (car mylist)) (A) > (list (cdr mylist)) ((B C D))

LISP is NOT case sensitive > (list (car mylist) (caddr mylist)) (A C) > mylist (A B C D) > (last mylist) ; as defined in the interpreter (D) > (cond ((null mylist) (print “ list is empty” ) ) ) NIL LISP is NOT case sensitive

> (cond ( (null mylist) (print “empty”)) ) > (equal ‘A ‘a) T > (cond ( (null mylist) (print “empty”)) ( t (print “not empty”) ) ) “not empty” Action print “not empty” Return “not empty”

> (cond ( (null mylist) (print “empty”)) ) ( t mylist ) ) (A B C D) > (defun second (l ) (cadr l)) SECOND (second mylist) B

> (list (second mylist) (car mylist) (cddr mylist) ) (B A (C D)) Get the last element of a list Define this function Recursive definition

Define a function to reverse a list