Common Lisp! - PowerPoint PPT Presentation

About This Presentation
Title:

Common Lisp!

Description:

The continental divide runs through the state of Montana in ... Bannock was the territorial capitol. Iteration. dotimes. dolist. do. do* dotimes (setf sum 0) ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 14
Provided by: Joh7
Category:
Tags: bannock | common | lisp

less

Transcript and Presenter's Notes

Title: Common Lisp!


1
Common Lisp!
  • John Paxton
  • Montana State University
  • Summer 2003

2
Montana Geography
  • The continental divide runs through the state of
    Montana in the Rocky Mountains. On the west,
    water flows to the Pacific Ocean. On the east,
    water flows to the Gulf of Mexico.
  • The longest undammed river in the U.S., the
    Yellowstone River, is in Montana.

3
Montana Statehood
  • Montana was the 41st state to join the United
    States. It did so in 1889.
  • Bannock was the territorial capitol.

4
Iteration
  • dotimes
  • dolist
  • do
  • do

5
dotimes
  • gt (setf sum 0)
  • 0
  • gt (dotimes (i 10 sum)
  • (setf sum ( sum i))
  • )
  • 45

6
dotimes
  • Question. Write a function that computes the
    Fibonacci numbers using dotimes.
  • Question. Compile the above function and run it.

7
dolist
  • gt (setf sum 0)
  • 0
  • gt (dolist (item '(1 2 3) sum)
  • (setf sum ( sum item))
  • )
  • 6

8
dolist
  • Question. Write a function called my-mapcar that
    is equivalent to mapcar. The function should use
    the dolist construct.

9
do
  • (do
  • (
  • (local-variable-1 initial-value update)
  • (local-variable-n initial-value update)
  • )
  • (termination-test intermediate-forms result)
  • loop-body
  • )

10
do
  • gt (do
  • (
  • (sum 0)
  • (counter 0 ( 1 counter))
  • )
  • ( (gt counter 10) sum )
  • (setf sum ( sum counter))
  • )
  • 45

11
do
  • Question Write a function that computes the
    Fibonacci numbers using do.

12
do
  • do works just like do. The only difference is
    that the local variables are assigned initial
    values and updated in sequence instead of in
    parallel.

13
do
  • Question Write a function that computes the
    Fibonacci numbers using do.
Write a Comment
User Comments (0)
About PowerShow.com