From c99d7ab890b5c2652235b6bb97fc305cdcc46309 Mon Sep 17 00:00:00 2001 From: Stas Boukarev Date: Wed, 15 Jul 2015 04:42:10 +0300 Subject: [PATCH] Fix MAP1. Don't try to modify NIL. --- src/code/list.lisp | 5 +++-- tests/map-tests.impure.lisp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/code/list.lisp b/src/code/list.lisp index 5b00a5ce1..927bb53c5 100644 --- a/src/code/list.lisp +++ b/src/code/list.lisp @@ -1255,8 +1255,9 @@ (setf (car l) (cdar l))) (setq res (apply fun args)) (case accumulate - (:nconc (setf (cdr temp) res - temp (last res))) + (:nconc (when res + (setf (cdr temp) res + temp (last res)))) (:list (setf (cdr temp) (list res) temp (cdr temp)))))) diff --git a/tests/map-tests.impure.lisp b/tests/map-tests.impure.lisp index 34582f361..1b116ef13 100644 --- a/tests/map-tests.impure.lisp +++ b/tests/map-tests.impure.lisp @@ -227,3 +227,21 @@ `(lambda (type x) (map type #'identity x))) '(vector (signed-byte 16) 1) '(1.0)) type-error)) + +(with-test (:name :map-out-of-line) + (flet ((call (map &rest args) + (apply (compile nil `(lambda (&rest args) + (declare (notinline ,map)) + (apply #',map args))) + args))) + (assert (equal (call 'mapcar #'+ '(1 2 3) '(3 2 1)) + '(4 4 4))) + (assert (equal (call 'maplist #'cons '(1 2 3) '(3 2 1)) + '(((1 2 3) 3 2 1) ((2 3) 2 1) ((3) 1)))) + (assert (equal (call 'mapcan #'cons '(1 2 3) '(3 2 1)) + '(1 2 3 . 1))) + (assert (equal (call 'mapcon #'list '(1 2 3) '(3 2 1)) + '((1 2 3) (3 2 1) (2 3) (2 1) (3) (1)))) + (assert (equal (call 'mapcan #'identity + '((3 4 . 5) nil (1 . 5))) + '(3 4 1 . 5))))) -- 2.11.4.GIT