X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ecmalisp.lisp;h=c512603c9588d3c94c82a82b0c597f242c0a0d5f;hb=9281acfa396bd6e9570318cf08625268818243d6;hp=1754c193a6badd4aed50c8f8d033d2b45660db0e;hpb=7f5bf57bb7837297e531968713250158fad0c7b3;p=jscl.git diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 1754c19..c512603 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -263,13 +263,14 @@ (defun append (&rest lists) (!reduce #'append-two lists '())) - (defun reverse-aux (list acc) - (if (null list) - acc - (reverse-aux (cdr list) (cons (car list) acc)))) + (defun revappend (list1 list2) + (while list1 + (push (car list1) list2) + (setq list1 (cdr list1))) + list2) (defun reverse (list) - (reverse-aux list '())) + (revappend list '())) (defun list-length (list) (let ((l 0)) @@ -310,29 +311,29 @@ (defun listp (x) (or (consp x) (null x))) + (defun nthcdr (n list) + (while (and (plusp n) list) + (setq n (1- n)) + (setq list (cdr list))) + list) + (defun nth (n list) - (cond - ((null list) list) - ((zerop n) (car list)) - (t (nth (1- n) (cdr list))))) + (car (nthcdr n list))) (defun last (x) - (if (consp (cdr x)) - (last (cdr x)) - x)) + (while (consp (cdr x)) + (setq x (cdr x))) + x) (defun butlast (x) (and (consp (cdr x)) (cons (car x) (butlast (cdr x))))) (defun member (x list) - (cond - ((null list) - nil) - ((eql x (car list)) - list) - (t - (member x (cdr list))))) + (while list + (when (eql x (car list)) + (return list)) + (setq list (cdr list)))) (defun remove (x list) (cond