Common Lisp! John Paxton Montana State University Summer 2003
Textbook Lisp, 3 rd Edition Winston, Horn Addison-Wesley 1989
Where is Montana?
Where is Bozeman?
Why Lisp? Interpreted environment Editing and debugging tools Built on many years of experience Code and data have same form Lisp = List Processing
Lisp Myths It’s slow Programs are large Requires expensive computers Hard to read Hard to learn
Terminology atom, e.g. 1 list, e.g. ‘(1 2 3) s-expression
Comment ;; Line comments start with two semicolons.
first > (first '(1 2 3)) 1 second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth
rest > (rest '(1 2 3)) (2 3) > (rest 'apple) *** - REST: APPLE is not a list
setf > (setf location 'san-salvador) SAN-SALVADOR > location SAN-SALVADOR
cons > (cons 1 '(2 3)) (1 2 3) > (cons '(1) '(2 3)) ((1) 2 3)
append > (append '(1) '(2 3)) (1 2 3) > (append 1 '(2 3)) *** - APPEND: 1 is not a list (append '(1) 2) (1. 2)
list > (list 1) (1) > (list ) ( )
length > (length 'apple) *** - LENGTH: APPLE is not a sequence > (length '( )) 4
reverse > (reverse '(1 2 3)) (3 2 1) > (reverse '((1 2) 3)) (3 (1 2))
assoc > (assoc 'mister '((miss senorita) (mister senor))) (MISTER SENOR)
nthcdr (nthcdr 0 '(1 2 3)) (1 2 3) > (nthcdr 1 '(1 2 3)) (2 3) > (nthcdr 4 '(1 2 3)) NIL
butlast > (butlast '(1 2 3) 0) (1 2 3) > (butlast '(1 2 3) 1) (1 2) > (butlast '(1 2 3) 4) NIL
last > (last '(1 2 3)) (3)
Mathematical Operators + - * / > (+ 2 (* 3 4)) 14
Mathematical Functions round float max min expt sqrt abs
Questions 1.How do you invoke CLISP? 2.How do you exit CLISP? 3.What happens when you enter 5? 4.What happens when you enter ‘vertigo? 5.What happens when you enter vertigo? 6.What happens when you enter ‘(vertigo notorious).
Questions 7.What happens when you enter (vertigo notorious) ? 8.Give the variable movies the value ‘(vertigo notorious). 9.Access the first element of movies. 10.Access all of the elements of movies except for the first element. 11.What is t? What is nil?
Questions 12.Add spellbound to the front of movies. 13.Add spellbound to the end of movies. 14.Use list, append, and cons to build the list ‘(plantain guava). 15.Determine how many items are in movies. 16.Change movies so that the movies are listed in reverse order.
Questions 17.Calculate the sum of 2 plus Calculate the sum of 2 plus 3 plus Write an expression that uses the quadratic formula to calculate one of the roots of x 2 + x – 6 = What happens when you make an error? 21.How do you recover from an error?