From: David Vázquez Date: Fri, 8 Feb 2013 22:47:13 +0000 (+0100) Subject: Iterative MAPCAR X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=6f98aac6382d655a64592bd32395b55f8854d46c;p=jscl.git Iterative MAPCAR --- diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 9951c03..cdf33d0 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -350,10 +350,14 @@ (concat-two s1 s2)) (defun mapcar (func list) - (if (null list) - '() - (cons (funcall func (car list)) - (mapcar func (cdr list))))) + (let* ((head (cons 'sentinel nil)) + (tail head)) + (while (not (null list)) + (let ((new (cons (funcall func (car list)) nil))) + (rplacd tail new) + (setq tail new + list (cdr list)))) + (cdr head))) (defun identity (x) x)