From 6f98aac6382d655a64592bd32395b55f8854d46c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Fri, 8 Feb 2013 23:47:13 +0100 Subject: [PATCH] Iterative MAPCAR --- ecmalisp.lisp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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) -- 1.7.10.4