Created
July 6, 2013 23:36
-
-
Save JonathanSmith/5941673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun rmap-over-list (function list) | |
(when list | |
(cons (funcall function (first list)) | |
(rmap-over-list function (cdr list))))) | |
(defun imap-over-list (function list) | |
(loop for value in list collect (funcall function value))) | |
(defun add7 (number) (+ number 7)) | |
(defun sub7 (number) (- number 7)) | |
(rmap-over-list #'add7 '(1 2 3 4 5)) | |
(rmap-over-list #'sub7 '(1 2 3 4 5)) | |
(imap-over-list #'add7 '(1 2 3 4 5)) | |
(imap-over-list #'sub7 '(1 2 3 4 5)) | |
(mapcar #'add7 '(1 2 3 4 5)) | |
(mapcar #'sub7 '(1 2 3 4 5)) | |
;;CL-USER> (rmap-over-list #'add7 '(1 2 3 4 5)) | |
;;(8 9 10 11 12) | |
;;CL-USER> (imap-over-list #'add7 '(1 2 3 4 5)) | |
;;(8 9 10 11 12) | |
;;CL-USER> (mapcar #'add7 '(1 2 3 4 5)) | |
;;(8 9 10 11 12) | |
;;CL-USER> (mapcar #'sub7 '(1 2 3 4 5)) | |
;;(-6 -5 -4 -3 -2) | |
;;CL-USER> (imap-over-list #'sub7 '(1 2 3 4 5)) | |
;;(-6 -5 -4 -3 -2) | |
;;CL-USER> (rmap-over-list #'sub7 '(1 2 3 4 5)) | |
;;(-6 -5 -4 -3 -2) | |
;;CL-USER> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment