Getting Started with 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

ANSI Common Lisp 5. Control 16 June Blocks -- progn progn > (progn (format t “a”) (format t “b”) ( )) ab 23 The expressions within its body.
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 COSC3306: Programming Paradigms Lecture 11: Applicative Programming with Lisp Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
Lisp Recitation (cse471/598 Fall 2007 ) Aravind Kalavagattu.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
First Lecture on Introductory Lisp Yun Peng. Why Lisp? Because it’s the most widely used AI programming language Because AI researchers and theoreticians.
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)
CSE S. Tanimoto Explicit Function Application 1 Explicit Application of Functions, Functional Arguments and Explicit Evaluation Implicit and explicit.
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 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.
Yu-Tzu Lin ( 林育慈 )
Input/Output Chapters 7 & 9. Output n Print produces output > (print 100) n It also returns the value it printed –that’s where the second 100 came.
The Case primitive: matches the evaluated key form against the unevaluated keys by using eql The general format of case is the following: (case (... ).....
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.
Common lisp A functional programming language. Useful URL:
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
Iteration Chapters 6 & 7. Iteration in LISP n LISP (unlike Prolog) allows iteration –mapcar, remove-if(-not), count-if, find-if for special purpose iteration.
06 INPUT AND OUTPUT Functional Programming. Streams Two kinds of streams  Character streams  Binary streams Character streams are Lisp objects representing.
The Loop Macro Many of the CL “functions” are actually macros (let, progn, if, etc) The most complicated macro in CL is probably the Loop macro –The Loop.
Lisp Files, Arrays, and Macros CIS 479/579 Bruce R. Maxim UM-Dearborn.
Course roster management in scheme Data to be managed – A class roster is list of student entries of the form (ID, name, grade) – Example (“001”, “John.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
PRACTICAL COMMON LISP Peter Seibel 1.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Control Structures CSC 358/ Outline Midterm Lab #3 Homework #4 Sequential structures Conditional structures Unconditional branching Iteration.
Functional Programming. Some Functional Languages Lisp Scheme - a dialect of Lisp Haskell Miranda.
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.
 If you want to open an already existing file select file->open on the menu and then choose the program you want to modify. If you want to open a new.
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
Section 15.4, 15.6 plus other materials
Example of formula (defun roots (a b c) (list
Organization of Programming Languages
CS 326 Programming Languages, Concepts and Implementation
LISP LISt Processing.
LISP A brief overview.
Nondeterministic Evaluation
First Lecture on Introductory Lisp
Modern Programming Languages Lecture 21 Fakhar Lodhi
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE S. Tanimoto Explicit Function Application
Streams, Delayed Evaluation and a Normal Order Interpreter
LISP A brief overview.
John McCarthy Pioneer in AI Also Lisp Formalize common-sense reasoning
Defining Functions with DEFUN
LISP LISt Processing.
Abstraction and Repetition
Functional Programming: Lisp
Lecture # , , , , מבוא מורחב.
LISP LISt Processing.
Modern Programming Languages Lecture 18 Fakhar Lodhi
Common Lisp II.
Programming Languages
The general format of case is the following: (case <key form>
Presentation transcript:

Getting Started with Lisp 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, but your programs should run on the general for grading purposes. If you absolutely must use a different version and find that your version is not compatible with the version on the general, contact the TA before you turn in any work and make alternate arrangements.

Lisp on the General Allegro Common Lisp 4.3.1 is available on the general. The general is the “general purpose” Unix account all ASU students have access to. You can access it with ssh at general.asu.edu. Once you logon to the general, you will get a Unix prompt. At the prompt, type in the command “cl” to start Common Lisp.

The Lisp Prompt Lisp is an interactive, interpreted language. You can interact with it by entering commands at its command prompt, or by telling it to read in a file of commands. Every command entered, either at the prompt or read from a file, is immediately evaluated and executed by the interpreter.

Basic Commands (exit) or :exit - Exits the Lisp interpreter (load “file”) or :ld file– Loads and evaluates a file. Ctrl+C – Breaks execution if you get stuck. :help – Shows list of interpreter commands :reset – Starts the interpreter over :pop – Goes up one level of error breaks

Manipulating Lists Using Quote:- e.g.: USER(1): ‘(1 2 3) (1 2 3) Using CAR:- e.g.: USER(2): (CAR ‘( 1 2 3 4)) 1 Using CDR:- e.g.:- USER(3): (CDR ‘( 1 2 3)) ( 2 3)

Using Lists II Cons – (cons a b) – adds the element a to the head of the list b e.g. (cons ‘a ‘(b c)) gives (a b c) Append – (append a b …) – Creates a new list out of a set of lists e.g. (append '(a b c) '() '(d e f)) gives (a b c d e f)

ITERATION Using dolist :- dolist repeats a set of operations for as many times as there are entries in a list. E.g.:-USER(1): (dolist (x ‘(a b c)) (print x)) A B C NIL

Using LOOP E.g.:- USER(15):- (loop for x from 1 to 7 collect x) (1 2 3 4 5 6 7)

Using dotimes :- dotimes repeats an evaluation as many times as it is requested E.g.:- USER(10):-(dotimes (i 5 i) (print i)) o 1 2 3 4 5

Conditional Expressions:- Using CASE. E.g.:- User(10):(defun goose (x) (case x (1 ‘one) (2 ‘two) (3 ‘three) (4 ‘four) (otherwise ‘many))) goose

Defining functions using “defun” USER(1):(defun funct1 (x) (+ x 1)) FUNCT1 USER(2):(funct1(3)) 4

RECURSION LISP supports recursion just like any procedural language(eg: C) E.g.: Raise X to the Nth power (defun raise (x n) (if (= n 0) 1 (* x ( raise x (- n 1) ) ) ) )

Creating Variables Using ‘setf’ – to create global variables User(10): (setf var ‘element) element User(10): var let – to create local variables

Input and Output > (progn (format t “Please enter your name: ”) (read-line)) > (prin1 “hello”) > (format nil “Dear ~A, ~% Our records indicate …” “Mr. Malatesta”) Note: There are many variants. You need to refer to a CL book.

Other Important Lisp Concepts conditional operators – if, cond logical operators – and, or, not, unless mappings lambda functions arrays structures