Merge pull request #89 from Strigoides/subseq
authorDavid Vázquez <davazp@gmail.com>
Fri, 10 May 2013 15:24:24 +0000 (08:24 -0700)
committerDavid Vázquez <davazp@gmail.com>
Fri, 10 May 2013 15:24:24 +0000 (08:24 -0700)
SUBSEQ implementation for lists

src/compiler.lisp
src/list.lisp
src/toplevel.lisp
tests/list.lisp

index be10266..3fe2823 100644 (file)
     ((floatp sexp) (float-to-string sexp))
     ((characterp sexp) (code "\"" (escape-string (string sexp)) "\""))
     (t
-     (or (cdr (assoc sexp *literal-table* :test #'equal))
+     (or (cdr (assoc sexp *literal-table* :test #'eql))
          (let ((dumped (typecase sexp
                          (symbol (dump-symbol sexp))
                          (string (dump-string sexp))
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 544022f..0698a0b 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))))