Common Lisp! - PowerPoint PPT Presentation

About This Presentation
Title:

Common Lisp!

Description:

Write a function called blackjack that receives two card names as inputs. ... For example, (blackjack ace jack) would return blackjack. Questions ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 25
Provided by: Joh7
Category:
Tags: blackjack | common | lisp

less

Transcript and Presenter's Notes

Title: Common Lisp!


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
  • gt (add-ten 7)
  • 17

6
let
  • gt (let ((a 1)(b 2))
  • ( a b)
  • )
  • 3
  • gt ( a b)
  • - EVAL variable A has no value

7
let
  • gt (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
  • gt (member '(1 2) '((1 1)(1 2)(1 3)) test
    'equal)
  • ((1 2) (1 3))

13
Other Predicates
  • listp
  • atom
  • numberp
  • symbolp
  • null
  • endp
  • gt, lt, gt, lt

14
Boolean Operators
  • and
  • or
  • not

15
if statement
  • (if (gt 2 3) 'bigger)
  • NIL
  • gt (if (gt 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
  • ((gt temperature 30) 'hot)
  • ((gt 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
  1. Define a function that shows a practical use of a
    cond statement.
  2. Define a function that shows a practical use of a
    case statement.
  3. Define a function that shows a practical use of
    nested conditional statements.

21
Underlying Representation
  • (1 2 3)

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

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

24
Questions
  1. Depict what happens below (setf list1 (1
    2)) (setf list2 (3)) (setf list3 (append list1
    list2))
  2. Depict what happens below (setf alist (1 2
    3)) (setf (second alist) 4)
Write a Comment
User Comments (0)
About PowerShow.com