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 Montana Statistics 2001 Population: 904,433. In contrast, El Salvador has a population of 6,353,681. 90.6% White 6.2% Native American 2.0% Hispanic or Latino Bozeman Population: 27,509.

3 Montana Statistics Land Area: 376,980 square kilometers. In contrast, El Salvador has 21,040 square kilometers. Fun fact: The greatest recorded 24 hour temperature change occurred in Loma, Montana in 1972. The temperature rose from -49 F to 54 F!

4 Material Defining Functions Local Variables Using Files Predicates Boolean Operands Lisp Representation

5 defun (defun add-ten (n) (+ n 10) ) ADD-TEN > (add-ten 7) 17

6 let > (let ((a 1)(b 2)) (+ a b) ) 3 > (+ a b) - EVAL: variable A has no value

7 let* > (let* ((a 1)(b (+ a 1))) (+ a b) ) 3

8 Using Files (load “file-name.l”) (load “file-name.lsp”) (compile-file “file-name.l”) (load “file-name”)

9 Questions 1.Write a function called gringo-dictionary that finds the spanish equivalent for an english word passed in. 2.Write a function that returns the roots of a quadratic equation in a list. For example, (roots 1 5 6) might return ‘(-2 - 3).

10 Boolean Values t = any non-empty list nil = ‘() = ()

11 Equality Predicates =(= 3 4) eq(eq ‘(1 2) ‘(1 2)) (setf a ‘(1 2)) (eq a a) equal(equal ‘(1 2) ‘(1 2))

12 member Predicate (member '(1 2) '((1 1)(1 2)(1 3))) NIL > (member '(1 2) '((1 1)(1 2)(1 3)) :test #'equal) ((1 2) (1 3))

13 Other Predicates listp atom numberp symbolp null endp >, =, <=

14 Boolean Operators and or not

15 if statement (if (> 2 3) 'bigger) NIL > (if (> 2 3) 'bigger 'not-bigger) NOT-BIGGER

16 cond statement (cond (test1 statement 1 … statement n) (test2 statement 1 … statement m) … (testk statement 1.. statement p) )

17 cond statement (cond ((> temperature 30) 'hot) ((> temperature 25) 'warm) (t 'pleasant) )

18 case statement (case temperature (35 ‘hot) (34 ‘hot) … (otherwise ‘pleasant) )

19 Questions 1.Write a function called blackjack that receives two card names as inputs. If one card is an ace and the other is a jack, the function should return the message blackjack. For example, (blackjack ‘ace ‘jack) would return ‘blackjack.

20 Questions 2.Define a function that shows a practical use of a cond statement. 3.Define a function that shows a practical use of a case statement. 4.Define a function that shows a practical use of nested conditional statements.

21 Underlying Representation ‘(1 2 3) 1 2 3

22 Underlying Representation ‘(1 (2) 3) 1 3 2

23 Questions 1.Draw the representation of ‘(1 (2 3 (4)) 5) 2.Draw the representation of ‘(defun add-one (n) (+ n 1)) 3.Depict what happens below (setf list1 ‘(2 3)) (setf list2 ‘(cons 1 list1))

24 Questions 4.Depict what happens below (setf list1 ‘(1 2)) (setf list2 ‘(3)) (setf list3 (append list1 list2)) 5.Depict what happens below (setf alist ‘(1 2 3)) (setf (second alist) 4)


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

Similar presentations


Ads by Google