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 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 41 st state to join the United States. It did so in 1889. Bannock was the territorial capitol.

4 Iteration dotimes dolist do do*

5 dotimes > (setf sum 0) 0 > (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 > (setf sum 0) 0 > (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 > (do ( (sum 0) (counter 0 (+ 1 counter)) ) ( (>= 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*.


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

Similar presentations


Ads by Google