1 / 11

Common Lisp!

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!.

saber
Download Presentation

Common Lisp!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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.

More Related