Add support for mapc
authorAlfredo Beaumont <alfredo.beaumont@gmail.com>
Thu, 9 May 2013 20:30:28 +0000 (22:30 +0200)
committerAlfredo Beaumont <alfredo.beaumont@gmail.com>
Thu, 9 May 2013 20:30:28 +0000 (22:30 +0200)
src/list.lisp
src/toplevel.lisp
tests/list.lisp

index 7a4ca6d..d515e52 100644 (file)
                (rplaca tail (cdar tail)))
              (collect (apply func elems))))))))
 
+(defun mapc (func &rest lists)
+  (do* ((elems (map1 #'car lists) (map1 #'car lists-rest))
+        (lists-rest (map1 #'cdr lists) (map1 #'cdr lists-rest)))
+       ((dolist (x elems) (when (null x) (return t)))
+        (car lists))
+    (apply func elems)))
+
 (defun last (x)
   (while (consp (cdr x))
     (setq x (cdr x)))
index b5ef24b..9e94336 100644 (file)
@@ -65,7 +65,7 @@
           get-universal-time go identity if in-package incf integerp intern
           intersection keywordp labels lambda last length let let*
           lisp-implementation-type list list* list-all-packages listp loop
-          make-array make-package make-symbol mapcar member minusp mod
+          make-array make-package make-symbol mapc mapcar member minusp mod
           multiple-value-bind multiple-value-call multiple-value-list
           multiple-value-prog1 nconc nil ninth not nreconc nth nthcdr null
           numberp or otherwise package-name package-use-list packagep pairlis
index 2f1b57c..9bb2996 100644 (file)
@@ -87,3 +87,9 @@
              (bar (pop foo)))
         (and (= bar 1)
              (= (car foo) 2))))
+
+;; MAPC
+(test (equal (mapc #'+ '(1 2) '(3) '(4 5 6)) '(1 2)))
+(test (let (foo)
+        (mapc (lambda (x y z) (print (list x y z)) (push (+ x y z) foo)) '(1 2) '(3) '(4 5 6))
+        (equal foo '(8))))