Presentation is loading. Please wait.

Presentation is loading. Please wait.

Common Lisp! John Paxton Montana State University Summer 2003.

Similar presentations


Presentation on theme: "Common Lisp! John Paxton Montana State University Summer 2003."— Presentation transcript:

1 Common Lisp! John Paxton Montana State University Summer 2003

2 Textbook Lisp, 3 rd Edition Winston, Horn Addison-Wesley 1989

3 Where is Montana?

4 Where is Bozeman?

5 Why Lisp? Interpreted environment Editing and debugging tools Built on many years of experience Code and data have same form Lisp = List Processing

6 Lisp Myths It’s slow Programs are large Requires expensive computers Hard to read Hard to learn

7 Terminology atom, e.g. 1 list, e.g. ‘(1 2 3) s-expression

8 Comment ;; Line comments start with two semicolons.

9 first > (first '(1 2 3)) 1 second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth

10 rest > (rest '(1 2 3)) (2 3) > (rest 'apple) *** - REST: APPLE is not a list

11 setf > (setf location 'san-salvador) SAN-SALVADOR > location SAN-SALVADOR

12 cons > (cons 1 '(2 3)) (1 2 3) > (cons '(1) '(2 3)) ((1) 2 3)

13 append > (append '(1) '(2 3)) (1 2 3) > (append 1 '(2 3)) *** - APPEND: 1 is not a list (append '(1) 2) (1. 2)

14 list > (list 1) (1) > (list 1 2 3 4) (1 2 3 4)

15 length > (length 'apple) *** - LENGTH: APPLE is not a sequence > (length '(1 2 3 4)) 4

16 reverse > (reverse '(1 2 3)) (3 2 1) > (reverse '((1 2) 3)) (3 (1 2))

17 assoc > (assoc 'mister '((miss senorita) (mister senor))) (MISTER SENOR)

18 nthcdr (nthcdr 0 '(1 2 3)) (1 2 3) > (nthcdr 1 '(1 2 3)) (2 3) > (nthcdr 4 '(1 2 3)) NIL

19 butlast > (butlast '(1 2 3) 0) (1 2 3) > (butlast '(1 2 3) 1) (1 2) > (butlast '(1 2 3) 4) NIL

20 last > (last '(1 2 3)) (3)

21 Mathematical Operators + - * / > (+ 2 (* 3 4)) 14

22 Mathematical Functions round float max min expt sqrt abs

23 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).

24 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?

25 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.

26 Questions 17.Calculate the sum of 2 plus 3. 18.Calculate the sum of 2 plus 3 plus 4. 19.Write an expression that uses the quadratic formula to calculate one of the roots of x 2 + x – 6 = 0. 20.What happens when you make an error? 21.How do you recover from an error?


Download ppt "Common Lisp! John Paxton Montana State University Summer 2003."

Similar presentations


Ads by Google