110 likes | 245 Views
Common Lisp!. John Paxton Montana State University Summer 2003. 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!.
E N D
Common Lisp! John Paxton Montana State University Summer 2003
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!
Mapping • funcall • apply • mapcar • remove-if, remove-if-not • count-if • find-if • lambda
funcall > (funcall #'append '(1 2) '(3 4)) (1 2 3 4)
apply > (apply #'append '((1 2)(3 4))) (1 2 3 4)
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.
mapcar (defun my-mapcar (fn alist) (if (null alist) nil (cons (funcall fn (first alist)) (my-mapcar fn (rest alist))) ) )
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.
count-if > (count-if #'oddp '(1 2 3)) 2 Question: Write a recursive version called my-count-if.
find-if > (find-if #'oddp '(1 2 3)) 1 Question: Write a recursive function called my-find-if.
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.