From: David Vazquez Date: Fri, 28 Dec 2012 01:37:07 +0000 (+0000) Subject: LAST and BUTLAST work for improper lists X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=7a3b48bc54c5540a963c6aca4c974ca90c41bfca;p=jscl.git LAST and BUTLAST work for improper lists --- diff --git a/lispstrack.lisp b/lispstrack.lisp index 5b71994..562f004 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -273,14 +273,13 @@ (t (nth (1- n) (cdr list))))) (defun last (x) - (if (null (cdr x)) - x - (last (cdr x)))) + (if (consp (cdr x)) + (last (cdr x)) + x)) (defun butlast (x) - (if (null (cdr x)) - nil - (cons (car x) (butlast (cdr x))))) + (and (consp (cdr x)) + (cons (car x) (butlast (cdr x))))) (defun member (x list) (cond