common lisp! john paxton montana state university summer 2003
TRANSCRIPT
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.
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!
Material
• Defining Functions
• Local Variables
• Using Files
• Predicates
• Boolean Operands
• Lisp Representation
Using Files
• (load “file-name.l”)
• (load “file-name.lsp”)
• (compile-file “file-name.l”)
• (load “file-name”)
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).
Equality Predicates
• = (= 3 4)
• eq (eq ‘(1 2) ‘(1 2))
(setf a ‘(1 2))(eq a a)
• equal (equal ‘(1 2) ‘(1 2))
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))
cond statement
(cond
(test1 statement 1 … statement n)
(test2 statement 1 … statement m)
…
(testk statement 1 .. statement p)
)
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.
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.
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))