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 Facts Did you know that Montana had no speed limits on its interstate highways until May 28, 1999? Did you know that Montana has the shortest river in the world? The Roe River near Great Falls is just 58 feet long!

3 Mapping funcall apply mapcar remove-if, remove-if-not count-if find-if lambda

4 funcall > (funcall #'append '(1 2) '(3 4)) (1 2 3 4)

5 apply > (apply #'append '((1 2)(3 4))) (1 2 3 4)

6 mapcar > (mapcar #'oddp '(1 2 3)) (T NIL T) Question: Write a recursive function called my-mapcar that produces the same results as mapcar, but does not use mapcar.

7 mapcar (defun my-mapcar (fn alist) (if (null alist) nil (cons (funcall fn (first alist)) (my-mapcar fn (rest alist))) )

8 remove-if, remove-if-not > (remove-if #'oddp '(1 2 3)) (2) > (remove-if-not #'oddp '(1 2 3)) (1 3) Question: Write a recursive function called my-remove-if.

9 count-if > (count-if #'oddp '(1 2 3)) 2 Question: Write a recursive version called my-count-if.

10 find-if > (find-if #'oddp '(1 2 3)) 1 Question: Write a recursive function called my-find-if.

11 lambda > (mapcar #'(lambda (n) (+ n 1)) '(1 2 3)) (2 3 4) Used for anonymous, one-time functions. I don’t use them very often.


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

Similar presentations


Ads by Google