Skip to content

Address #196: Fix issues with mapping and nconc accumulation

Carl Shapiro requested to merge cshapiro/cmucl:mapcan into master

This change reorders the accumulation so the next tail is saved before the current tail is appended using rplacd. This makes the behavior of mapcan equivalent to the following

(defun mapcan (f x) (cond ((null x) nil) (t (nconc (funcall f (car x)) (mapcan f (cdr x))))))

in the one argument case, which is consistent with other Lisp systems including Maclisp, where the mapcan function seems to have originated.

In doing so, this change resolves two of the defects reported in the aforementioned issue. First, it checks the value being accumulated ensure it satisfies listp. Second, it allows the creation of a circular list under certain conditions, consistent with the recursive definition shown above.

Merge request reports