TES3111 October 2001 Artificial Intelligence LISP.

Slides:



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

1 Programming Languages and Paradigms Lisp Programming.
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.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
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 -
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Data types and variables
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Introduction to C Programming
Basic Elements of C++ Chapter 2.
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.
Yu-Tzu Lin ( 林育慈 )
Objectives You should be able to describe: Data Types
A First Book of ANSI C Fourth Edition
High-Level Programming Languages: C++
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Input, Output, and Processing
Introduction to Scheme Lectures on The Scheme Programming Language, 2 nd Ed. R. Kent Dybvig.
Computer Science 101 Introduction to Programming.
Artificial Intelligence IES 503 Asst. Prof. Dr. Senem Kumova Metin.
C++ Programming: Basic Elements of C++.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 5.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Looping and Counting Lecture 3 Hartmut Kaiser
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Introduction to Computer Programming
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Introduction to LISP Atoms, Lists Math. LISP n LISt Processing n Function model –Program = function definition –Give arguments –Returns values n Mathematical.
CPS120: Introduction to Computer Science Variables and Constants.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (n-n-n-notes) Summer 2003 Dr. Carter Tiernan.
Functional Programming
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
Java Primer 1: Types, Classes and Operators
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Basic Elements of C++.
Types and Values.
CS 326 Programming Languages, Concepts and Implementation
The Selection Structure
LISP LISt Processing.
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Topics Designing a Program Input, Processing, and Output
INTRODUCTION TO MATLAB
Topics Designing a Program Input, Processing, and Output
LISP LISt Processing.
Topics Designing a Program Input, Processing, and Output
Introduction to Computer Science
LISP LISt Processing.
Modern Programming Languages Lecture 18 Fakhar Lodhi
Lexical Elements & Operators
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

TES3111 October 2001 Artificial Intelligence LISP

TES3111 October 2001 Lisp resources We will use an implementation of LISP called Allegro Common LISP. Different LISP interpreters include - Eg interpreter: Allegro LISP, Harlequin LISP, Corman Lisp.  Text books:  ANSI Common LISP, P.Graham, Prentice Hall, 1995 (recommended)  Common LISP:the language, G.L. Steele, Digital Press, 1990 (2nd Edition)

TES3111 October 2001 Lisp resources-cont  Common LISP: A gentle introduction to Symbolic Computing, David Touretzky, Addison Wesley,  Paradigms of Artificial Intelligence Programming: Case Studies in Common LISP, Peter Norvig, Academic Press/Morgan Kaufmann, 1992.

TES3111 October 2001 Useful websites for LISP Allegro Lisp download – Association of LISP users – Common LISP Open Code Collection – AI special interest group of the ACM - –

TES3111 October Lisp is interactive There is an interpreter that evaluates inputs. An input is processes in 3 steps: 1. Reads input and construct expression from the input. 2. Evaluates the expression for meaning. 3. Prints the results of the evaluation, including signaling of erros if necessary. These 3 steps can be customized by the programmer.

TES3111 October Lisp is a dynamic language Programs are developed incrementally, by making small changes to the source code. Interpreter evaluates the changed definitions and then immediately run the results. New definitions and data structures can be added at any time. This features are ideal for prototyping.

TES3111 October Lisp has symbols Symbols are the basic type of data in use. Symbols are used to build bigger, more complex expressions. Example of symbols: –HELLO –23-worldofsports

TES3111 October LISP has lists Lists are delimited using parenthesis (…). Anything can be placed in a list, including other lists (nested lists). For example: (1 orange 2 3) (once (upon a) time) Empty list is represented as () Caution: elements within a list are separated with a white space, and NOT a comma,

TES3111 October Lisp classifies data It does not classify variables. A variable is just a symbol. It can hold any type of value. A variable do not have to be declared before it is used. Lisp defines different types of data (rather than defining different types of variables)

TES3111 October Lisp classifies data - contd Lisp Expression numbersymbolsequence integer float ratio keyword listvector string

TES3111 October Lisp classifies data - contd Integer - a counting number like 1, 2,3 …100, -23 float - real number. Example 1.59, ratio - a fraction, example 99/23, 4/5 symbol - a sequence of alphanumeric characters, eg: BOO, ID4… keyword - a symbol prefixed with a colon. Eg- :BOO, :ID4 list - a collection of zero or m ore expressions inside (..) vector - 1 dimensional collection of expressions in sequential memory string - a vector of 0 or more characters inside “ ”

TES3111 October Lisp uses prefix notation Operators appear in front of their operands. The infix (10 + 3) is written as (+ 10 3)

TES3111 October Lisp is functional Lisp functions take data, operates on it, and return the results. The returned results are called function values. Functions can return any number of values. To call a function, place it as the first element of an input list, followed by its operands. Example: ( ) (setf x (+ 2 3)) All operations are done through functions

TES3111 October Programs and data Lisp makes no distinction between programs and data. A program can be treated as a set of instruction or as a list of symbols. This makes it possible to write programs that generate another program, or programs that analyze other programs.

TES3111 October Lisp evaluation is easy to understand Rule 1 : If an expression is a constant, the interpreter will return the value of the constant. No more rules apply. Examples: ‘socrates, 4.5 Rule 2: If Rule 1 is not applicable, and the expression is a symbol, then Lisp treats the symbol as a variable and no more rules are considered. If the variable has a value, Lisp will return that value. Otherwise it will report an error.

TES3111 October Lisp evaluation is easy to understand Rule 3: If Rule 1 and Rule 2 do not apply and the expression is a LIST, then Lisp treats it as a function call and no more rules are considered. –You should at this point remember that the first element in the list is assumed to be a defined a function. The remaining elements are data. Each expression in the data is evaluated left to right. Rule 4: If Rules 1 to 3 do not apply, then there is an error!

TES3111 October Lisp is easy to learn??? How to study and program in Lisp? –Read the first few chapters of a good introductory Lisp book. –Read up the definition of each Lisp function that you encounter. –Start developing a good programming style from the very start!

TES3111 October 2001 Data Structures S-Expression - Symbolic expression. It can be an Atom, a List or a collection of S- Expression enclosed by (…) Atom - String of characters beginning with a letter, digit. Eg: Artificial, intelligence, etc.

TES3111 October 2001 Data Structures List - a collection of S-Expression enclosed by ( …. ). Eg: (One of these days) (one ((two) three) four)

TES3111 October 2001 Basic Operations üA LISP program contains functions applied to its arguments. üFunctions return LISP objects. ü2 types of functions - PREDICATE and COMMANDS

TES3111 October 2001 Predicate A function that tests for some condition involving its arguments and returns –Nil if the condition is FALSE (Nil stands for FALSE) –True for any other case. In LISP TRUE is represented using a special LISP variable T.

TES3111 October 2001 Command A command performs operations on its arguments and returns an S-expression. Format of a command is: ( Arg1 Arg2 … Argn) Note: All commands and predicates must be enclosed in (…). To differentiate from lists… a list is preceded with a single quote ‘ Eg : (CAR a b c) versus ‘(CAR a b c)

TES3111 October 2001 Function - CAR CAR - returns the first element of a list. Examples: (CAR ‘(a b c d e)) (CAR ‘((an orange) a day)) (CAR '(1 (2 3 (4 5)) 6)) (CAR ‘()) Note that in the last example, the argument to CAR is a null- list.