From 7a3b48bc54c5540a963c6aca4c974ca90c41bfca Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Fri, 28 Dec 2012 01:37:07 +0000 Subject: [PATCH] LAST and BUTLAST work for improper lists --- lispstrack.lisp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 -- 1.7.10.4